|
| 1 | +import org.junit.jupiter.api.BeforeAll; |
| 2 | +import org.junit.jupiter.api.TestInstance; |
| 3 | +import org.junit.jupiter.params.ParameterizedTest; |
| 4 | +import org.junit.jupiter.params.provider.MethodSource; |
| 5 | + |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 10 | + |
| 11 | +@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
| 12 | +public class TestAnalyzeUserWebsiteVisitPattern |
| 13 | +{ |
| 14 | + private AnalyzeUserWebsiteVisitPattern analyzeUserWebsiteVisitPattern; |
| 15 | + |
| 16 | + @BeforeAll |
| 17 | + public void setUp() |
| 18 | + { |
| 19 | + analyzeUserWebsiteVisitPattern = new AnalyzeUserWebsiteVisitPattern(); |
| 20 | + } |
| 21 | + |
| 22 | + private static Object[][] testAnalyzeUserWebsiteVisitPatternDataProvider() |
| 23 | + { |
| 24 | + return new Object[][] { |
| 25 | + {new String[] {"joe", "joe", "joe", "james", "james", "james", "james", "mary", "mary", "mary"}, |
| 26 | + new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, |
| 27 | + new String[] {"home", "about", "career", "home", "cart", "maps", "home", "home", "about", "career"}, |
| 28 | + Arrays.asList("home", "about", "career")}, |
| 29 | + {new String[] {"ua", "ua", "ua", "ub", "ub", "ub"}, |
| 30 | + new int[] {1, 2, 3, 4, 5, 6}, |
| 31 | + new String[] {"a", "b", "a", "a", "b", "c"}, |
| 32 | + Arrays.asList("a", "b", "a")} |
| 33 | + }; |
| 34 | + } |
| 35 | + |
| 36 | + @ParameterizedTest |
| 37 | + @MethodSource("testAnalyzeUserWebsiteVisitPatternDataProvider") |
| 38 | + public void testLeastNumberOfUniqueIntegersAfterKRemovals(String[] username, int[] timestamp, String[] website, List<String> expectation) |
| 39 | + { |
| 40 | + List<String> ret = analyzeUserWebsiteVisitPattern.mostVisitedPattern(username, timestamp, website); |
| 41 | + assertEquals(expectation.size(), ret.size()); |
| 42 | + for (int i = 0; i < ret.size(); ++i) { |
| 43 | + assertEquals(expectation.get(i), ret.get(i)); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments