Skip to content

Commit

Permalink
🧪 test: Add test cases for GE, LE, LT
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed Oct 31, 2024
1 parent c8a44d5 commit 096171a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scripts/ts/test/test.logical.operations.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { type float, double, int, long } from "./test.type.aliases.ts";

class Test {
public logicalGE_II_Z(a: int, b: int): boolean {
return a >= b;
}

public logicalGT_II_Z(a: int, b: int): boolean {
return a > b;
}

public logicalLE_II_Z(a: int, b: int): boolean {
return a <= b;
}

public logicalLT_II_Z(a: int, b: int): boolean {
return a < b;
}
}

console.log(new Test().logicalGE_II_Z(1, 2));
console.log(new Test().logicalGT_II_Z(1, 2));
console.log(new Test().logicalLE_II_Z(1, 2));
console.log(new Test().logicalLT_II_Z(1, 2));
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ public boolean logicalGT_II_Z(int a, int b) {
return a > b;
}

@Test
public void testLogicalGE_II_Z() throws Exception {
Method method = clazz.getMethod("logicalGE_II_Z", int.class, int.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(int.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertFalse((boolean) method.invoke(object, 1, 2));
assertTrue((boolean) method.invoke(object, 2, 1));
assertTrue((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalGT_II_Z() throws Exception {
assertFalse(logicalGT_II_Z(1, 2));
Expand All @@ -95,4 +109,31 @@ public void testLogicalGT_II_Z() throws Exception {
assertFalse((boolean) method.invoke(object, 1, 2));
assertTrue((boolean) method.invoke(object, 2, 1));
}

@Test
public void testLogicalLE_II_Z() throws Exception {
Method method = clazz.getMethod("logicalLE_II_Z", int.class, int.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(int.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1, 2));
assertFalse((boolean) method.invoke(object, 2, 1));
assertTrue((boolean) method.invoke(object, 1, 1));
}

@Test
public void testLogicalLT_II_Z() throws Exception {
Method method = clazz.getMethod("logicalLT_II_Z", int.class, int.class);
assertNotNull(method);
assertEquals(boolean.class, method.getReturnType());
assertEquals(2, method.getParameterCount());
assertEquals(int.class, method.getParameters()[0].getType());
assertEquals(int.class, method.getParameters()[1].getType());
Object object = clazz.getConstructor().newInstance();
assertTrue((boolean) method.invoke(object, 1, 2));
assertFalse((boolean) method.invoke(object, 2, 1));
}
}

0 comments on commit 096171a

Please sign in to comment.