Add tests for CellPattern & GameOfLife classes
This commit is contained in:
parent
8afb45e33e
commit
2993b33d9e
3 changed files with 55 additions and 2 deletions
|
@ -1,10 +1,17 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class CellPattern<Point> extends DelegatingList<Point> {
|
||||
class CellPattern extends DelegatingList<Point> {
|
||||
final String _name;
|
||||
CellPattern(String name, List base)
|
||||
CellPattern(String name, List<Point> base)
|
||||
: _name = name,
|
||||
super(base);
|
||||
|
||||
String get name => _name;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "$name: ${super.toString()}";
|
||||
}
|
||||
}
|
||||
|
|
19
test/src/rules/cellpattern_test.dart
Normal file
19
test/src/rules/cellpattern_test.dart
Normal file
|
@ -0,0 +1,19 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:rules_of_living/src/rules/CellPattern.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
CellPattern sut;
|
||||
setUp(() {
|
||||
sut = CellPattern("testPattern", [Point(1, 1), Point(0, 0), Point(-1, -1)]);
|
||||
});
|
||||
group("Naming", () {
|
||||
test("contains the name passed in for name variable",
|
||||
() => expect(sut.name, "testPattern"));
|
||||
test(
|
||||
"Contains the name passed in on being formatted as String",
|
||||
() => expect(sut.toString(),
|
||||
"testPattern: [Point(1, 1), Point(0, 0), Point(-1, -1)]"));
|
||||
});
|
||||
}
|
27
test/src/rules/gameoflife_test.dart
Normal file
27
test/src/rules/gameoflife_test.dart
Normal file
|
@ -0,0 +1,27 @@
|
|||
import 'package:rules_of_living/src/rules/GameOfLife.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
GameOfLife sut;
|
||||
setUp(() {
|
||||
sut = GameOfLife();
|
||||
});
|
||||
group("BirthRules", () {
|
||||
test("will return true when being passed three neighbors",
|
||||
() => expect(sut.checkBirth(3), true));
|
||||
test("will return false when being passed zero neighbors",
|
||||
() => expect(sut.checkBirth(0), false));
|
||||
test("will return false when being passed two neighbors",
|
||||
() => expect(sut.checkBirth(2), false));
|
||||
});
|
||||
group("SurviveRules", () {
|
||||
test("will return true when being passed two neighbors",
|
||||
() => expect(sut.checkSurvival(2), true));
|
||||
test("will return true when being passed three neighbors",
|
||||
() => expect(sut.checkSurvival(3), true));
|
||||
test("will return false when being passed 0 neighbors",
|
||||
() => expect(sut.checkSurvival(0), false));
|
||||
test("will return false when being passed more than 3 neighbors",
|
||||
() => expect(sut.checkSurvival(4), false));
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue