Project

General

Profile

Actions

Tmp » History » Revision 2

« Previous | Revision 2/6 (diff) | Next »
Николай Пакулин, 03/30/2015 05:56 PM


Кусочки кода

static void assertTestString(CharSequence s) {
        int pos = 0;
        int len = s.length();
        int rest = 0;
        char fill = 0;

        for (pos = 0; pos < len; pos++) {
            if (rest == 0) {
                fill = s.charAt(pos);
                if (fill == 0) {
                    continue;
                }
                rest = fill - 1;
                continue;
            } else {
                assertEquals("Position " + pos + ": expected symbol \\u" 
                        + new Integer(fill) + " got \\u" 
                        + new Integer(s.charAt(pos))
                    , fill, s.charAt(pos));
                rest --;
            }
        }
        assertEquals("expected "+ rest + " more characters", 
                0, rest);
    }

@Test
public void testAssert() {
assertTestString("\u0000");
assertTestString("\u0001");
assertTestString("\u0002\u0002\u0003\u0003\u0003");
} @Test
public void testAssertFail() {
String[] tests = new String[] {
"\u0002",
"\u0002\u0002\u0003"
};
for (int i = 0; i < tests.length; i++) {
try{
assertTestString(tests[i]);
}catch (AssertionError e) {
continue;
}
fail("Missed wrong string {" + tests[i] + "}");
}
}

Updated by Николай Пакулин about 9 years ago · 2 revisions