|
|
@ -16,24 +16,15 @@ void t.test("getSequenceOutcome", async (t) => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
void t.test("all sequences of length 2", async (t) => { |
|
|
|
void t.test("all sequences of length 2", async (t) => { |
|
|
|
t.equal( |
|
|
|
t.equal(getSequenceOutcome([SquareState.Unoccupied, SquareState.Unoccupied]), null); |
|
|
|
getSequenceOutcome([SquareState.Unoccupied, SquareState.Unoccupied]), |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal(getSequenceOutcome([SquareState.Unoccupied, SquareState.X]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.Unoccupied, SquareState.X]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.Unoccupied, SquareState.O]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.Unoccupied, SquareState.O]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.X, SquareState.Unoccupied]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.X, SquareState.Unoccupied]), null); |
|
|
|
t.equal( |
|
|
|
t.equal(getSequenceOutcome([SquareState.X, SquareState.X]), CurrentOutcome.WinX); |
|
|
|
getSequenceOutcome([SquareState.X, SquareState.X]), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal(getSequenceOutcome([SquareState.X, SquareState.O]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.X, SquareState.O]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.O, SquareState.Unoccupied]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.O, SquareState.Unoccupied]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.O, SquareState.X]), null); |
|
|
|
t.equal(getSequenceOutcome([SquareState.O, SquareState.X]), null); |
|
|
|
t.equal( |
|
|
|
t.equal(getSequenceOutcome([SquareState.O, SquareState.O]), CurrentOutcome.WinO); |
|
|
|
getSequenceOutcome([SquareState.O, SquareState.O]), |
|
|
|
|
|
|
|
CurrentOutcome.WinO, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
void t.test("sequences of length 7", async (t) => { |
|
|
|
void t.test("sequences of length 7", async (t) => { |
|
|
@ -135,211 +126,69 @@ void t.test("getSequenceOutcome", async (t) => { |
|
|
|
|
|
|
|
|
|
|
|
void t.test("getBoardOutcome", async (t) => { |
|
|
|
void t.test("getBoardOutcome", async (t) => { |
|
|
|
void t.test("1x1 boards", async (t) => { |
|
|
|
void t.test("1x1 boards", async (t) => { |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_")), CurrentOutcome.Undecided); |
|
|
|
getBoardOutcome(Board.fromSerialized("_")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("X")), CurrentOutcome.Draw); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("X")), CurrentOutcome.Draw); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("O")), CurrentOutcome.Draw); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("O")), CurrentOutcome.Draw); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
void t.test("2x2 boards", async (t) => { |
|
|
|
void t.test("2x2 boards", async (t) => { |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("__|__")), CurrentOutcome.Undecided); |
|
|
|
getBoardOutcome(Board.fromSerialized("__|__")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XX|X_")), CurrentOutcome.Undecided); |
|
|
|
CurrentOutcome.Undecided, |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XX|XX")), CurrentOutcome.Draw); |
|
|
|
); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("OO|OO")), CurrentOutcome.Draw); |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XO|OX")), CurrentOutcome.Draw); |
|
|
|
getBoardOutcome(Board.fromSerialized("XX|X_")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XX|XX")), |
|
|
|
|
|
|
|
CurrentOutcome.Draw, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("OO|OO")), |
|
|
|
|
|
|
|
CurrentOutcome.Draw, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XO|OX")), |
|
|
|
|
|
|
|
CurrentOutcome.Draw, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
void t.test("3x3 boards", async (t) => { |
|
|
|
void t.test("3x3 boards", async (t) => { |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("___|___|___")), CurrentOutcome.Undecided); |
|
|
|
getBoardOutcome(Board.fromSerialized("___|___|___")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("___|_X_|___")), CurrentOutcome.Undecided); |
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XX_|___|___")), CurrentOutcome.Undecided); |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("___|___|_XX")), CurrentOutcome.Undecided); |
|
|
|
getBoardOutcome(Board.fromSerialized("___|_X_|___")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("X__|X__|___")), CurrentOutcome.Undecided); |
|
|
|
CurrentOutcome.Undecided, |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("___|__X|__X")), CurrentOutcome.Undecided); |
|
|
|
); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("X__|_X_|___")), CurrentOutcome.Undecided); |
|
|
|
|
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("___|_X_|__X")), CurrentOutcome.Undecided); |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("__X|_X_|___")), CurrentOutcome.Undecided); |
|
|
|
getBoardOutcome(Board.fromSerialized("XX_|___|___")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("___|_X_|X__")), CurrentOutcome.Undecided); |
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XXX|O_O|O_O")), CurrentOutcome.WinX); |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("O_O|O_O|XXX")), CurrentOutcome.WinX); |
|
|
|
getBoardOutcome(Board.fromSerialized("___|___|_XX")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XOO|X__|XOO")), CurrentOutcome.WinX); |
|
|
|
CurrentOutcome.Undecided, |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("OOX|__X|OOX")), CurrentOutcome.WinX); |
|
|
|
); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XOO|OXO|OOX")), CurrentOutcome.WinX); |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("OOX|OXO|XOO")), CurrentOutcome.WinX); |
|
|
|
getBoardOutcome(Board.fromSerialized("X__|X__|___")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XXO|XOX|OXX")), CurrentOutcome.WinO); |
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XOX|XXO|OXO")), CurrentOutcome.Draw); |
|
|
|
getBoardOutcome(Board.fromSerialized("___|__X|__X")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XOX|XXO|OX_")), CurrentOutcome.Undecided); |
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("X__|_X_|___")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("___|_X_|__X")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("__X|_X_|___")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("___|_X_|X__")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XXX|O_O|O_O")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("O_O|O_O|XXX")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XOO|X__|XOO")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("OOX|__X|OOX")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XOO|OXO|OOX")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("OOX|OXO|XOO")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XXO|XOX|OXX")), |
|
|
|
|
|
|
|
CurrentOutcome.WinO, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XOX|XXO|OXO")), |
|
|
|
|
|
|
|
CurrentOutcome.Draw, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("XOX|XXO|OX_")), |
|
|
|
|
|
|
|
CurrentOutcome.Undecided, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
void t.test("5x5 boards", async (t) => { |
|
|
|
void t.test("5x5 boards", async (t) => { |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|_____|_____|_____")), CurrentOutcome.Undecided); |
|
|
|
getBoardOutcome(Board.fromSerialized("_____|_____|_____|_____|_____")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("XXX__|_____|_____|_____|_____")), CurrentOutcome.WinX); |
|
|
|
CurrentOutcome.Undecided, |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("X____|X____|X____|_____|_____")), CurrentOutcome.WinX); |
|
|
|
); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("X____|_X___|__X__|_____|_____")), CurrentOutcome.WinX); |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("__X__|_X___|X____|_____|_____")), CurrentOutcome.WinX); |
|
|
|
getBoardOutcome(Board.fromSerialized("XXX__|_____|_____|_____|_____")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|_____|_____|__XXX")), CurrentOutcome.WinX); |
|
|
|
); |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|____X|____X|____X")), CurrentOutcome.WinX); |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|__X__|___X_|____X")), CurrentOutcome.WinX); |
|
|
|
getBoardOutcome(Board.fromSerialized("X____|X____|X____|_____|_____")), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|____X|___X_|__X__")), CurrentOutcome.WinX); |
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("X____|_X___|__X__|_____|_____")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("__X__|_X___|X____|_____|_____")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("_____|_____|_____|_____|__XXX")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("_____|_____|____X|____X|____X")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("_____|_____|__X__|___X_|____X")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome(Board.fromSerialized("_____|_____|____X|___X_|__X__")), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
void t.test("6x5 boards", async (t) => { |
|
|
|
void t.test("6x5 boards", async (t) => { |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|_____|_____|_____|__XXX")), CurrentOutcome.WinX); |
|
|
|
getBoardOutcome( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|_____|____X|____X|____X")), CurrentOutcome.WinX); |
|
|
|
Board.fromSerialized("_____|_____|_____|_____|_____|__XXX"), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|_____|__X__|___X_|____X")), CurrentOutcome.WinX); |
|
|
|
), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("_____|_____|_____|____X|___X_|__X__")), CurrentOutcome.WinX); |
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome( |
|
|
|
|
|
|
|
Board.fromSerialized("_____|_____|_____|____X|____X|____X"), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome( |
|
|
|
|
|
|
|
Board.fromSerialized("_____|_____|_____|__X__|___X_|____X"), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome( |
|
|
|
|
|
|
|
Board.fromSerialized("_____|_____|_____|____X|___X_|__X__"), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
void t.test("5x6 boards", async (t) => { |
|
|
|
void t.test("5x6 boards", async (t) => { |
|
|
|
t.equal( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("______|______|______|______|___XXX")), CurrentOutcome.WinX); |
|
|
|
getBoardOutcome( |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("______|______|_____X|_____X|_____X")), CurrentOutcome.WinX); |
|
|
|
Board.fromSerialized("______|______|______|______|___XXX"), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("______|______|___X__|____X_|_____X")), CurrentOutcome.WinX); |
|
|
|
), |
|
|
|
t.equal(getBoardOutcome(Board.fromSerialized("______|______|_____X|____X_|___X__")), CurrentOutcome.WinX); |
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome( |
|
|
|
|
|
|
|
Board.fromSerialized("______|______|_____X|_____X|_____X"), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome( |
|
|
|
|
|
|
|
Board.fromSerialized("______|______|___X__|____X_|_____X"), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
t.equal( |
|
|
|
|
|
|
|
getBoardOutcome( |
|
|
|
|
|
|
|
Board.fromSerialized("______|______|_____X|____X_|___X__"), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CurrentOutcome.WinX, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|