-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrategy_test.dart
71 lines (56 loc) · 1.48 KB
/
strategy_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'package:test/test.dart';
class TestSubject {
final double pupilDiameter;
final double blushResponse;
final bool isOrganic;
TestSubject({
required this.pupilDiameter,
required this.blushResponse,
required this.isOrganic,
});
}
abstract class RealnessTesting {
bool testRealness(TestSubject testSubject);
}
class VoightKampffTest implements RealnessTesting {
@override
bool testRealness(TestSubject testSubject) {
return testSubject.pupilDiameter < 30.0 || testSubject.blushResponse != 0.0;
}
}
class GeneticTest implements RealnessTesting {
@override
bool testRealness(TestSubject testSubject) {
return testSubject.isOrganic;
}
}
class BladeRunner {
final RealnessTesting _strategy;
BladeRunner(this._strategy);
bool testIfAndroid(TestSubject testSubject) {
return !_strategy.testRealness(testSubject);
}
}
void main() {
TestSubject rachel = TestSubject(
pupilDiameter: 30.2,
blushResponse: 0.3,
isOrganic: false,
);
test("Deckard's method should return false for Rachel", () {
// given
BladeRunner deckard = BladeRunner(VoightKampffTest());
// when
bool isRachelAndroid = deckard.testIfAndroid(rachel);
// then
expect(isRachelAndroid, isFalse);
});
test("Gaff's method should return true for Rachel", () {
// given
BladeRunner gaff = BladeRunner(GeneticTest());
// when
bool isRachelAndroid = gaff.testIfAndroid(rachel);
// then
expect(isRachelAndroid, isTrue);
});
}