AdsOptimizationImpl implements AdsOptimization { @Override public AdsOptimization filterAds(Inventory inventory, float minRelevanceScore, float minReservePrice) { if (minRelevanceScore < 0 || minRelevanceScore > 1) { throw new IllegalArgumentException( "Minimum Relevance Score should be a number between 0 and 1."); } if (minReservePrice < 0) { throw new IllegalArgumentException( "Minimum Reserve Price should be a non-negtive number."); } if (inventory.size() == 0) { return this; } for (Iterator<AdsStatsInfo> iterator = _candidateAds.iterator(); iterator.hasNext();) { if (iterator.next().getRelevanceScore() < minRelevanceScore) { iterator.remove(); } } for (Iterator<AdsStatsInfo> iterator = _candidateAds.iterator(); iterator.hasNext();) { if (inventory.findAds(iterator.next().getAdsId()).getBid() < minReservePrice) { iterator.remove(); } } return this; } AdsOptimizationImpl(List<AdsStatsInfo> candidateAds); @Override List<AdsStatsInfo> filterCandidateAds(Inventory inventory, float minRelevanceScore, float minReservePrice); @Override AdsOptimization filterAds(Inventory inventory, float minRelevanceScore, float minReservePrice); @Override AdsOptimization selectTopK(int k); @Override AdsOptimization adsPricingAndAllocation(Inventory inventory, float mainlineReservePrice); @Override String toString(); @Override AdsOptimization deDup(); @Override boolean equals(Object o); @Override int hashCode(); @Override List<AdsStatsInfo> showResult();  }
@Test(expected = IllegalArgumentException.class) public void filterAdsShouldThrowIllegalArgumentException_For_MinRelevanceScoreLessThanZero() { System.out .println("filterAdsShouldThrowIllegalArgumentException_For_MinRelevanceScoreLessThanZero"); ads.filterAds(inventory, -1, 1); }
@Test(expected = IllegalArgumentException.class) public void filterAdsShouldThrowIllegalArgumentException_For_MinRelevanceScoreBiggerThanOne() { System.out .println("filterAdsShouldThrowIllegalArgumentException_For_MinRelevanceScoreBiggerThanOne"); ads.filterAds(inventory, 2, 1); }
@Test(expected = IllegalArgumentException.class) public void filterAdsShouldThrowIllegalArgumentException_For_MinReservePriceLessThanZero() { System.out .println("filterAdsShouldThrowIllegalArgumentException_For_MinReservePriceLessThanZero"); ads.filterAds(inventory, 1, -1); }
@Test @UseDataProvider("filterAdsData") public void filterAdsShouldReturnAValidOutput(float minRelevanceScore, float minReservePrice, AdsOptimizationImpl expected) { System.out.println("filterAdsShouldReturnAValidOutput"); AdsOptimization result = ads.filterAds(inventory, minRelevanceScore, minReservePrice); assertEquals(expected, result); }