From 2993b33d9e9e8135297f171b055d2c607f0fcd7f Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 19 Oct 2018 08:23:00 +0200 Subject: [PATCH] Add tests for CellPattern & GameOfLife classes --- lib/src/rules/CellPattern.dart | 11 +++++++++-- test/src/rules/cellpattern_test.dart | 19 +++++++++++++++++++ test/src/rules/gameoflife_test.dart | 27 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/src/rules/cellpattern_test.dart create mode 100644 test/src/rules/gameoflife_test.dart 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)); + }); +}