@Override public Collection<T> listSelectedVersions(List<T> allVersions) { if (this.isExcludeMode()) { return getBoundarySafeSublist(allVersions, this.getVersionsSelected(), allVersions.size()); } return getBoundarySafeSublist(allVersions, 0, this.getVersionsSelected()); }
@Test public void testCreationConfig() { for(Map.Entry<String, Map<String, Integer>> test: TEST_CONFIGS.entrySet()) { String testName = test.getKey(); Config conf = ConfigFactory.parseMap(test.getValue()); NewestKSelectionPolicy policy = new NewestKSelectionPolicy(conf); Assert.assertEquals(policy.getVersionsSelected(), Math.abs(TEST_RESULTS.get(testName).intValue()), "Failure for test " + testName); Assert.assertEquals(policy.isExcludeMode(), TEST_RESULTS.get(testName).intValue() < 0, "Failure for test " + testName); } for(Map.Entry<String, Map<String, Integer>> test: NEG_TEST_CONFIGS.entrySet()) { String testName = test.getKey(); Config conf = ConfigFactory.parseMap(test.getValue()); try { new NewestKSelectionPolicy(conf); Assert.fail("Exception expected for test " + testName); } catch (RuntimeException e) { // OK } } }
.withValue(NewestKSelectionPolicy.NEWEST_K_VERSIONS_SELECTED_KEY, ConfigValueFactory.fromAnyRef(5)); NewestKSelectionPolicy policy = new NewestKSelectionPolicy(conf); Collection<DatasetVersion> res = policy.listSelectedVersions(versions); int idx = 0; Assert.assertEquals(res.size(), policy.getVersionsSelected()); for (DatasetVersion v: res) { Assert.assertEquals(v, versions.get(idx++), "Mismatch for index " + idx); .withValue(NewestKSelectionPolicy.NEWEST_K_VERSIONS_SELECTED_KEY, ConfigValueFactory.fromAnyRef(15)); policy = new NewestKSelectionPolicy(conf); res = policy.listSelectedVersions(versions); idx = 0; Assert.assertEquals(res.size(), versions.size()); .withValue(NewestKSelectionPolicy.NEWEST_K_VERSIONS_NOTSELECTED_KEY, ConfigValueFactory.fromAnyRef(4)); policy = new NewestKSelectionPolicy(conf); res = policy.listSelectedVersions(versions); idx = policy.getVersionsSelected(); Assert.assertEquals(res.size(), versions.size() - policy.getVersionsSelected()); for (DatasetVersion v: res) { Assert.assertEquals(v, versions.get(idx++), "Mismatch for index " + idx); .withValue(NewestKSelectionPolicy.NEWEST_K_VERSIONS_NOTSELECTED_KEY, ConfigValueFactory.fromAnyRef(14)); policy = new NewestKSelectionPolicy(conf); res = policy.listSelectedVersions(versions);
@Test public void testCreationProps() { for(Map.Entry<String, Map<String, Integer>> test: TEST_CONFIGS.entrySet()) { String testName = test.getKey(); Properties testProps = new Properties(); for (Map.Entry<String, Integer> prop: test.getValue().entrySet()) { testProps.setProperty(prop.getKey(), prop.getValue().toString()); } NewestKSelectionPolicy policy = new NewestKSelectionPolicy(testProps); Assert.assertEquals(policy.getVersionsSelected(), Math.abs(TEST_RESULTS.get(testName).intValue()), "Failure for test " + testName); Assert.assertEquals(policy.isExcludeMode(), TEST_RESULTS.get(testName).intValue() < 0, "Failure for test " + testName); } for(Map.Entry<String, Map<String, Integer>> test: NEG_TEST_CONFIGS.entrySet()) { String testName = test.getKey(); Properties testProps = new Properties(); for (Map.Entry<String, Integer> prop: test.getValue().entrySet()) { testProps.setProperty(prop.getKey(), prop.getValue().toString()); } try { new NewestKSelectionPolicy(testProps); Assert.fail("Exception expected for test " + testName); } catch (RuntimeException e) { //OK } } }
@Override public Collection<T> listSelectedVersions(List<T> allVersions) { if (this.isExcludeMode()) { return getBoundarySafeSublist(allVersions, this.getVersionsSelected(), allVersions.size()); } return getBoundarySafeSublist(allVersions, 0, this.getVersionsSelected()); }