diff --git a/lib/src/rules/CellPattern.dart b/lib/src/rules/CellPattern.dart index 9798948..ed4cae7 100644 --- a/lib/src/rules/CellPattern.dart +++ b/lib/src/rules/CellPattern.dart @@ -1,10 +1,17 @@ +import 'dart:math'; + import 'package:collection/collection.dart'; -class CellPattern extends DelegatingList { +class CellPattern extends DelegatingList { final String _name; - CellPattern(String name, List base) + CellPattern(String name, List base) : _name = name, super(base); String get name => _name; + + @override + String toString() { + return "$name: ${super.toString()}"; + } } diff --git a/test/src/rules/cellpattern_test.dart b/test/src/rules/cellpattern_test.dart new file mode 100644 index 0000000..a7989f5 --- /dev/null +++ b/test/src/rules/cellpattern_test.dart @@ -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)]")); + }); +} diff --git a/test/src/rules/gameoflife_test.dart b/test/src/rules/gameoflife_test.dart new file mode 100644 index 0000000..565e4e1 --- /dev/null +++ b/test/src/rules/gameoflife_test.dart @@ -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)); + }); +}