|
| 1 | +package com.codedifferently.lesson11; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | + |
| 6 | +import java.util.Arrays; |
| 7 | +import java.util.List; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +class Lesson11Test { |
| 11 | + |
| 12 | + @Test |
| 13 | + public void testGetConcatenation() { |
| 14 | + Lesson11 solution = new Lesson11(); |
| 15 | + |
| 16 | + // Test case 1 |
| 17 | + int[] nums1 = {1, 2, 1}; |
| 18 | + int[] expected1 = {1, 2, 1, 1, 2, 1}; |
| 19 | + int[] result1 = solution.getConcatenation(nums1); |
| 20 | + assertArrayEquals(expected1, result1); |
| 21 | + |
| 22 | + // Test case 2 |
| 23 | + int[] nums2 = {1, 3, 2, 1}; |
| 24 | + int[] expected2 = {1, 3, 2, 1, 1, 3, 2, 1}; |
| 25 | + int[] result2 = solution.getConcatenation(nums2); |
| 26 | + assertArrayEquals(expected2, result2); |
| 27 | + |
| 28 | + // Test case 3 |
| 29 | + int[] nums3 = {}; |
| 30 | + int[] expected3 = {}; |
| 31 | + int[] result3 = solution.getConcatenation(nums3); |
| 32 | + assertArrayEquals(expected3, result3); |
| 33 | + |
| 34 | + // Test case 4 |
| 35 | + int[] nums4 = {5}; |
| 36 | + int[] expected4 = {5, 5}; |
| 37 | + int[] result4 = solution.getConcatenation(nums4); |
| 38 | + assertArrayEquals(expected4, result4); |
| 39 | + |
| 40 | + // Test case 5 |
| 41 | + int[] nums5 = {0, 0, 0}; |
| 42 | + int[] expected5 = {0, 0, 0, 0, 0, 0}; |
| 43 | + int[] result5 = solution.getConcatenation(nums5); |
| 44 | + assertArrayEquals(expected5, result5); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testWordsContainingChar() { |
| 49 | + Lesson11 solution = new Lesson11(); |
| 50 | + |
| 51 | + // Test case 1 |
| 52 | + char ch1 = 'a'; |
| 53 | + String[] words1 = {"apple", "banana", "cherry", "date"}; |
| 54 | + List<Integer> expected1 = Arrays.asList(0, 1, 3); |
| 55 | + List<Integer> result1 = solution.findWordsContaining(words1, ch1); |
| 56 | + assertEquals(expected1, result1); |
| 57 | + |
| 58 | + // Test case 2 |
| 59 | + char ch2 = 'z'; |
| 60 | + String[] words2 = {"apple", "banana", "cherry", "date"}; |
| 61 | + List<Integer> expected2 = Arrays.asList(); |
| 62 | + List<Integer> result2 = solution.findWordsContaining(words2, ch2); |
| 63 | + assertEquals(expected2, result2); |
| 64 | + |
| 65 | + // Test case 3 |
| 66 | + char ch3 = 'e'; |
| 67 | + String[] words3 = {"apple", "banana", "cherry", "date"}; |
| 68 | + List<Integer> expected3 = Arrays.asList(0, 2, 3); |
| 69 | + List<Integer> result3 = solution.findWordsContaining(words3, ch3); |
| 70 | + assertEquals(expected3, result3); |
| 71 | + |
| 72 | + // Test case 4 |
| 73 | + char ch4 = 'a'; |
| 74 | + String[] words4 = {"", " ", "banana"}; |
| 75 | + List<Integer> expected4 = Arrays.asList(2); |
| 76 | + List<Integer> result4 = solution.findWordsContaining(words4, ch4); |
| 77 | + assertEquals(expected4, result4); |
| 78 | + } |
| 79 | +} |
0 commit comments