add unit tests for State class
This commit is contained in:
parent
d53cd1d0ad
commit
55096079a7
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
/.rscons*
|
/.rscons*
|
||||||
/build/
|
/build/
|
||||||
/peg-puzzle
|
/peg-puzzle
|
||||||
|
/peg-puzzle-test
|
||||||
|
@ -3,8 +3,13 @@ configure do
|
|||||||
end
|
end
|
||||||
|
|
||||||
build do
|
build do
|
||||||
Environment.new do |env|
|
main_env = Environment.new do |env|
|
||||||
env["D_IMPORT_PATH"] << "src"
|
env["D_IMPORT_PATH"] << "src"
|
||||||
env.Program("peg-puzzle", glob("src/**/*.d"))
|
env["sources"] = glob("src/**/*.d")
|
||||||
|
env.Program("peg-puzzle", "${sources}")
|
||||||
|
end
|
||||||
|
test_env = main_env.clone do |env|
|
||||||
|
env["DFLAGS"] += %w[-g -funittest]
|
||||||
|
env.Program("peg-puzzle-test", "${sources}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
22
src/state.d
22
src/state.d
@ -33,4 +33,26 @@ class State
|
|||||||
{
|
{
|
||||||
return m_pegs[peg_index(row, col)];
|
return m_pegs[peg_index(row, col)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
State s = new State(5);
|
||||||
|
assert(s.valid_position(0, 0));
|
||||||
|
assert(s.valid_position(4, 0));
|
||||||
|
assert(s.valid_position(4, 4));
|
||||||
|
assert(s.valid_position(2, 2));
|
||||||
|
assert(s.valid_position(3, 1));
|
||||||
|
assert(!s.valid_position(0, 1));
|
||||||
|
assert(!s.valid_position(0, -1));
|
||||||
|
assert(!s.valid_position(5, 0));
|
||||||
|
assert(!s.valid_position(5, 4));
|
||||||
|
assert(!s.valid_position(4, 5));
|
||||||
|
assert(!s.valid_position(2, 3));
|
||||||
|
assert(!s.valid_position(0, 4));
|
||||||
|
|
||||||
|
assert(s.peg_present(1, 0));
|
||||||
|
assert(s.peg_present(1, 1));
|
||||||
|
assert(s.peg_present(4, 4));
|
||||||
|
assert(!s.peg_present(0, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user