package com.google.openlocationcode.tests;

import com.google.openlocationcode.OpenLocationCode;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/** Tests shortening functionality of Open Location Code. */
public class ShorteningTest {

  private class TestData {

    private final String code;
    private final double referenceLatitude;
    private final double referenceLongitude;
    private final String shortCode;

    public TestData(String line) {
      String[] parts = line.split(",");
      if (parts.length != 4) {
        throw new IllegalArgumentException("Wrong format of testing data.");
      }
      this.code = parts[0];
      this.referenceLatitude = Double.valueOf(parts[1]);
      this.referenceLongitude = Double.valueOf(parts[2]);
      this.shortCode = parts[3];
    }
  }

  private final List<TestData> testDataList = new ArrayList<>();

  @Before
  public void setUp() throws Exception {
    File testFile = new File(System.getenv("JAVA_RUNFILES"), "openlocationcode/test_data/shortCodeTests.csv");
    InputStream testDataStream = new FileInputStream(testFile);
    BufferedReader reader = new BufferedReader(new InputStreamReader(testDataStream));
    String line;
    while ((line = reader.readLine()) != null) {
      if (line.startsWith("#")) {
        continue;
      }
      testDataList.add(new TestData(line));
    }
  }

  @Test
  public void testShortening() {
    for (TestData testData : testDataList) {
      OpenLocationCode olc = new OpenLocationCode(testData.code);
      OpenLocationCode shortened =
          olc.shorten(testData.referenceLatitude, testData.referenceLongitude);
      Assert.assertEquals(
          "Wrong shortening of code " + testData.code,
          testData.shortCode,
          shortened.getCode());
    }
  }

  @Test
  public void testRecovering() {
    for (TestData testData : testDataList) {
      OpenLocationCode olc = new OpenLocationCode(testData.shortCode);
      OpenLocationCode recovered =
          olc.recover(testData.referenceLatitude, testData.referenceLongitude);
      Assert.assertEquals(testData.code, recovered.getCode());
    }
  }
}

@@ -638,16 +638,51 @@
 ortCode;
+%0A    private final String testType;
 %0A%0A    pu
@@ -780,9 +780,9 @@
  != 
-4
+5
 ) %7B%0A
@@ -1042,16 +1042,48 @@
 rts%5B3%5D;%0A
+      this.testType = parts%5B4%5D;%0A
     %7D%0A  
@@ -1723,32 +1723,124 @@
 testDataList) %7B%0A
+      if (testData.testType != %22B%22 && testData.testType != %22S%22) %7B%0A        continue;%0A      %7D%0A
       OpenLocati
@@ -2192,32 +2192,32 @@
 tRecovering() %7B%0A
-
     for (TestDat
@@ -2241,24 +2241,116 @@
 DataList) %7B%0A
+      if (testData.testType != %22B%22 && testData.testType != %22R%22) %7B%0A        continue;%0A      %7D%0A
       OpenLo

Update ShorteningTest.java