diff --git a/src/contests/contest30/SubarraySumEqualsK_JunitTest.java b/src/contests/contest30/SubarraySumEqualsK_JunitTest.java new file mode 100644 index 0000000..c01fb23 --- /dev/null +++ b/src/contests/contest30/SubarraySumEqualsK_JunitTest.java @@ -0,0 +1,73 @@ +package contests.contest30; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class SubarraySumEqualsK_JunitTest { + + @Test + void test0() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {1}; + int result = SSEK.subarraySum(arr, 1); + assertEquals(1, result); + } + + @Test + void test1() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {}; + int result = SSEK.subarraySum(arr, 8); + assertEquals(0, result); + } + + @Test + void test2() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {1,2,1}; + int result = SSEK.subarraySum(arr, 1); + assertEquals(2, result); + } + + @Test + void test3() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {1,2,3,4,5}; + int result = SSEK.subarraySum(arr, 0); + assertEquals(0, result); + } + + @Test + void test4() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {1,2,1}; + int result = SSEK.subarraySum(arr, 3); + assertEquals(2, result); + } + + @Test + void test5() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {1,-1,2,-2,-3,3}; + int result = SSEK.subarraySum(arr, 0); + assertEquals(6, result); + } + + @Test + void test6() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {-15,6,-3,-8,0,1,4,1,-2,4,3,-5,4}; + int result = SSEK.subarraySum(arr, 0); + assertEquals(5, result); + } + + @Test + void test7() { + SubarraySumEqualsK SSEK = new SubarraySumEqualsK(); + int [] arr = {-3,4,12,6,2,-5,-3,0,5,-8,5,6,9}; + int result = SSEK.subarraySum(arr, 8); + assertEquals(4, result); + } + +} diff --git a/src/problems/medium/GasStation_Test.java b/src/problems/medium/GasStation_Test.java new file mode 100644 index 0000000..c2b81b3 --- /dev/null +++ b/src/problems/medium/GasStation_Test.java @@ -0,0 +1,42 @@ +package problems.medium; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class GasStation_Test { + int [] a = {1,2,3,4,5}; + int [] b = {2,3,4,5,6}; + int [] c = {2,3,2,1,2}; + int [] d = {2,1,5,1,2}; + int [] e = {2,1,3,5,4}; + + @Test + void test0() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,b); + assertEquals(-1, result); + } + + @Test + void test1() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,c); + assertEquals(2, result); + } + + @Test + void test2() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,d); + assertEquals(3, result); + } + + @Test + void test3() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,e); + assertEquals(1, result); + } + +} diff --git a/src/problems/medium/GasStation_Test_All_DU_path.java b/src/problems/medium/GasStation_Test_All_DU_path.java new file mode 100644 index 0000000..592b686 --- /dev/null +++ b/src/problems/medium/GasStation_Test_All_DU_path.java @@ -0,0 +1,55 @@ +package problems.medium; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class GasStation_Test_All_DU_path { + int [] a = {4,1,2,2,5}; + int [] b = {2,5,3,4,3}; + int [] c = {6,2,4,3,5}; + int [] d = {5,2,1,2,3}; + int [] e = {3,1,4,2,1}; + int [] f = {4,1,3,1,4}; + + @Test + // Kiểm thử All-DU path cho biến totgas + void test0() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,b); + assertEquals(-1, result); + } + + @Test + // Kiểm thử All-DU path cho biến totcost + void test1() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,c); + assertEquals(-1, result); + } + + @Test + // Kiểm thử All-DU path cho biến current + void test2() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,d); + assertEquals(2, result); + } + + @Test + // Kiểm thử All-DU path cho biến current + void test3() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,e); + assertEquals(3, result); + } + + @Test + // Kiểm thử All-DU path cho biến k + void test4() { + GasStation gs = new GasStation(); + int result = gs.canCompleteCircuit(a,f); + assertEquals(3, result); + } + +}