Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Junit test for class SubarraySumEqualsK #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/contests/contest30/SubarraySumEqualsK_JunitTest.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
42 changes: 42 additions & 0 deletions src/problems/medium/GasStation_Test.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
55 changes: 55 additions & 0 deletions src/problems/medium/GasStation_Test_All_DU_path.java
Original file line number Diff line number Diff line change
@@ -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);
}

}