|
| 1 | +package com.fishercoder.firstthousand; |
| 2 | + |
| 3 | +import com.fishercoder.solutions.firstthousand._722; |
| 4 | +import org.junit.jupiter.api.BeforeEach; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import java.util.Arrays; |
| 8 | + |
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 10 | + |
| 11 | +public class _722Test { |
| 12 | + private static _722.Solution1 solution1; |
| 13 | + |
| 14 | + @BeforeEach |
| 15 | + public void setup() { |
| 16 | + solution1 = new _722.Solution1(); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + public void test1() { |
| 21 | + assertEquals(Arrays.asList("int main()", "{ ", " ", "int a, b, c;", "a = b + c;", "}"), solution1.removeComments(new String[]{"/*Test program */", "int main()", "{ ", " // variable declaration ", "int a, b, c;", "/* This is a test", " multiline ", " comment for ", " testing */", "a = b + c;", "}"})); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void test2() { |
| 26 | + assertEquals(Arrays.asList("ab"), solution1.removeComments(new String[]{"a/*comment", "line", "more_comment*/b"})); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void test3() { |
| 31 | + assertEquals(Arrays.asList("struct Node{", " ", " int size;", " int val;", "};"), |
| 32 | + solution1.removeComments(new String[]{"struct Node{", " /*/ declare members;/**/", " int size;", " /**/int val;", "};"})); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void test4() { |
| 37 | + assertEquals(Arrays.asList("main() {", " double s = 33;", " cout << s;", "}"), |
| 38 | + solution1.removeComments(new String[]{"main() {", "/* here is commments", " // still comments */", " double s = 33;", " cout << s;", "}"})); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void test5() { |
| 43 | + assertEquals(Arrays.asList("void func(int k) {", " k = k*2/4;", " k = k/2;*/", "}"), |
| 44 | + solution1.removeComments(new String[]{"void func(int k) {", "// this function does nothing /*", " k = k*2/4;", " k = k/2;*/", "}"})); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void test6() { |
| 49 | + assertEquals(Arrays.asList("a", "blank", "df"), |
| 50 | + solution1.removeComments(new String[]{"a//*b/*/c", "blank", "d/*/e/*/f"})); |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments