software-testing/project_task_sheets/phase_04/project_phase04_tasks/CheckTimeTests.java

68 lines
3.3 KiB
Java
Raw Normal View History

package com.alibaba.fastjson.parser;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.junit.Assert;
import org.junit.Test;
public class CheckTimeTests {
private boolean checkTime(JSONScanner scanner, char h0, char h1, char m0, char m1, char s0, char s1) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method checkTime = JSONScanner.class.getDeclaredMethod("checkTime", char.class, char.class, char.class, char.class, char.class, char.class);
checkTime.setAccessible(true);
return (Boolean)checkTime.invoke(scanner, h0, h1, m0, m1, s0, s1);
}
@Test
public void CheckTime_IC_Test() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JSONScanner scanner = new JSONScanner("");
// (h0 == '0') && (h1 < '0' || h1 > '9')
// First nested predicate
Assert.assertFalse(checkTime(scanner, '0', '+', '0', '0', '0', '0'));
Assert.assertFalse(checkTime(scanner, '0', '?', '0', '0', '0', '0'));
Assert.assertFalse(checkTime(scanner, '?', '5', '0', '0', '0', '0'));
// Second nested predicate
Assert.assertFalse(checkTime(scanner, '1', '+', '0', '0', '0', '0'));
Assert.assertFalse(checkTime(scanner, '1', '?', '0', '0', '0', '0'));
Assert.assertFalse(checkTime(scanner, '?', '5', '0', '0', '0', '0'));
// Third nested predicate
Assert.assertFalse(checkTime(scanner, '2', '+', '0', '0', '0', '0'));
Assert.assertFalse(checkTime(scanner, '2', '5', '0', '0', '0', '0'));
Assert.assertFalse(checkTime(scanner, '?', '5', '0', '0', '0', '0'));
// (m0 >= '0' && m0 <= '5') && (m1 < '0' || m1 > '9')
// First nested predicate
Assert.assertFalse(checkTime(scanner, '1', '3', '+', '5', '0', '0'));
Assert.assertFalse(checkTime(scanner, '1', '3', '6', '5', '0', '0'));
Assert.assertFalse(checkTime(scanner, '1', '3', '4', '+', '0', '0'));
Assert.assertFalse(checkTime(scanner, '1', '3', '4', '?', '0', '0'));
// (m0 == '6') && (m1 != '0')
// not P, not Q, P and Q
// Second nested predicate
Assert.assertFalse(checkTime(scanner, '1', '3', '6', '1', '0', '0'));
Assert.assertTrue(checkTime(scanner, '1', '3', '5', '0', '0', '0'));
// (s0 >= '0' && s0 <= '5') && (s1 < '0' || s1 > '9')
// First nested predicate
Assert.assertFalse(checkTime(scanner, '1', '3', '5', '0', '+', '5'));
Assert.assertFalse(checkTime(scanner, '1', '3', '5', '0', '6', '5'));
Assert.assertFalse(checkTime(scanner, '1', '3', '5', '0', '4', '+'));
Assert.assertFalse(checkTime(scanner, '1', '3', '5', '0', '4', '?'));
}
@Test
public void CheckTime_Branch_Test() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
JSONScanner scanner = new JSONScanner("");
// (h0 == '0') && (h1 < '0' || h1 > '9')
// Missing branches
Assert.assertTrue(checkTime(scanner, '0', '5', '0', '0', '0', '0'));
Assert.assertTrue(checkTime(scanner, '2', '4', '0', '0', '0', '0'));
Assert.assertTrue(checkTime(scanner, '1', '4', '6', '0', '6', '0'));
}
}