예제 #1
0
        private static void selfTest()
        {
            selfTested = true;
            Reach r1 = new Reach("ab");
            Reach r2 = new Reach("..X--XX___XX,,XX");
            Reach r3 = new Reach("aa bb  cc ");

            ass(r3.firstWord(" ").equals(""));
            ass(r3.firstWord(" a").equals("aa "));
            ass(r3.lastWord(" ").equals(" "));

            ass(r2.upto(1, false, "X,", "X_", "X-").equals("..X-"));
            ass(r2.upto(2, false, "X,", "X_", "X-").equals("..X--XX_"));
            ass(r2.upto(3, false, "X,", "X_", "X-").equals("..X--XX___XX,"));
            ass(r2.upto(-1, false, "X,", "X_", "X-").equals("..X--XX___XX,"));
            ass(r2.upto(-2, false, "X,", "X_", "X-").equals("..X--XX_"));
            ass(r2.upto(-3, false, "X,", "X_", "X-").equals("..X-"));

            ass(r2.upto(1, false, ",XX", "_XX", "X-", "..").equals(".."));
            ass(r2.upto(2, false, ",XX", "_XX", "X-", "..").equals("..X-"));
            ass(r2.upto(3, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX"));
            ass(r2.upto(-1, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX,,XX"));
            ass(r2.upto(-2, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX"));
            ass(r2.upto(-3, false, ",XX", "_XX", "X-", "..").equals("..X-"));

            ass(r2.from(1, false, "X,", "X_", "X-").equals("X--XX___XX,,XX"));
            ass(r2.from(2, false, "X,", "X_", "X-").equals("X___XX,,XX"));
            ass(r2.from(3, false, "X,", "X_", "X-").equals("X,,XX"));
            ass(r2.from(-1, false, "X,", "X_", "X-").equals("X,,XX"));
            ass(r2.from(-2, false, "X,", "X_", "X-").equals("X___XX,,XX"));
            ass(r2.from(-3, false, "X,", "X_", "X-").equals("X--XX___XX,,XX"));

            ass(r2.from(1, false, ",XX", "_XX", "X-", "..").equals("..X--XX___XX,,XX"));
            ass(r2.from(2, false, ",XX", "_XX", "X-", "..").equals("X--XX___XX,,XX"));
            ass(r2.from(3, false, ",XX", "_XX", "X-", "..").equals("_XX,,XX"));
            ass(r2.from(-1, false, ",XX", "_XX", "X-", "..").equals(",XX"));
            ass(r2.from(-2, false, ",XX", "_XX", "X-", "..").equals("_XX,,XX"));
            ass(r2.from(-3, false, ",XX", "_XX", "X-", "..").equals("X--XX___XX,,XX"));

            ass(r1.upto(1).equals("a")); ass(r1.before(1).equals("")); ass(r1.from(1).equals("ab")); ass(r1.after(1).equals("b")); ass(r1.upto(-1).equals("ab")); ass(r1.before(-1).equals("a")); ass(r1.from(-1).equals("b")); ass(r1.after(-1).equals(""));

            ass(r2.upto(2, true, "XX").equals("..X--XX___XX")); ass(r2.upto(2, true, "X").equals("..X--X")); ass(r2.upto(2, true, "XX", "X").equals("..X--X")); ass(r2.upto(2, true, "X", "XX").equals("..X--X")); ass(r2.upto(-2, true, "XX").equals("..X--XX___XX")); ass(r2.upto(-2, true, "X").equals("..X--XX___XX,,X")); ass(r2.upto(-2, true, "XX", "X").equals("..X--XX___XX,,X")); ass(r2.upto(-2, true, "X", "XX").equals("..X--XX___XX,,X"));
            ass(r2.from(2, true, "XX").equals("XX,,XX")); ass(r2.from(2, true, "X").equals("XX___XX,,XX")); ass(r2.from(2, true, "XX", "X").equals("XX___XX,,XX")); ass(r2.from(2, true, "X", "XX").equals("XX___XX,,XX")); ass(r2.from(-2, true, "XX").equals("XX,,XX")); ass(r2.from(-2, true, "X").equals("XX")); ass(r2.from(-2, true, "XX", "X").equals("XX")); ass(r2.from(-2, true, "X", "XX").equals("XX"));
            ass(r2.before(2, true, "XX").equals("..X--XX___")); ass(r2.before(2, true, "X").equals("..X--")); ass(r2.before(2, true, "XX", "X").equals("..X--")); ass(r2.before(2, true, "X", "XX").equals("..X--")); ass(r2.before(-2, true, "XX").equals("..X--XX___")); ass(r2.before(-2, true, "X").equals("..X--XX___XX,,")); ass(r2.before(-2, true, "XX", "X").equals("..X--XX___XX,,")); ass(r2.before(-2, true, "X", "XX").equals("..X--XX___XX,,"));
            ass(r2.after(2, true, "XX").equals(",,XX")); ass(r2.after(2, true, "X").equals("X___XX,,XX")); ass(r2.after(2, true, "XX", "X").equals("X___XX,,XX")); ass(r2.after(2, true, "X", "XX").equals("X___XX,,XX")); ass(r2.after(-2, true, "XX").equals(",,XX")); ass(r2.after(-2, true, "X").equals("X")); ass(r2.after(-2, true, "XX", "X").equals("X")); ass(r2.after(-2, true, "X", "XX").equals("X"));
            ass(r2.at(2, true, "XX").equals("XX")); ass(r2.at(2, true, "X").equals("X")); ass(r2.at(2, true, "XX", "X").equals("X")); ass(r2.at(2, true, "X", "XX").equals("X")); ass(r2.at(-2, true, "XX").equals("XX")); ass(r2.at(-2, true, "X").equals("X")); ass(r2.at(-2, true, "XX", "X").equals("X")); ass(r2.at(-2, true, "X", "XX").equals("X"));
        }