-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathLaboratoryTest.php
89 lines (77 loc) · 3.37 KB
/
LaboratoryTest.php
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
use Scientist\Report;
use Scientist\Laboratory;
class LaboratoryTest extends \PHPUnit\Framework\TestCase
{
public function test_laboratory_can_be_created()
{
$l = new Laboratory;
$this->assertInstanceOf(Laboratory::class, $l);
}
public function test_laboratory_can_run_experiment_with_no_journals()
{
$v = (new Laboratory)
->experiment('test experiment')
->control(function () { return 'foo'; })
->trial('trial name', function () { return 'foo'; })
->run();
$this->assertEquals('foo', $v);
}
public function test_laboratory_can_fetch_report_for_experiment_with_no_journals()
{
$r = (new Laboratory)
->experiment('test experiment')
->control(function () { return 'foo'; })
->trial('trial', function () { return 'bar'; })
->report();
$this->assertInstanceOf(Report::class, $r);
$this->assertEquals('foo', $r->getControl()->getValue());
$this->assertEquals('bar', $r->getTrial('trial')->getValue());
$this->assertIsFloat($r->getControl()->getStartTime());
$this->assertIsFloat($r->getControl()->getEndTime());
$this->assertIsFloat($r->getControl()->getTime());
$this->assertIsFloat($r->getTrial('trial')->getStartTime());
$this->assertIsFloat($r->getTrial('trial')->getEndTime());
$this->assertIsFloat($r->getTrial('trial')->getTime());
$this->assertIsInt($r->getControl()->getStartMemory());
$this->assertIsInt($r->getControl()->getEndMemory());
$this->assertIsInt($r->getControl()->getMemory());
$this->assertIsInt($r->getTrial('trial')->getStartMemory());
$this->assertIsInt($r->getTrial('trial')->getEndMemory());
$this->assertIsInt($r->getTrial('trial')->getMemory());
$this->assertNull($r->getControl()->getException());
$this->assertNull($r->getTrial('trial')->getException());
$this->assertFalse($r->getTrial('trial')->isMatch());
}
public function test_that_exceptions_are_thrown_within_control()
{
$this->expectException(Exception::class);
$v = (new Laboratory)
->experiment('test experiment')
->control(function () { throw new Exception; })
->trial('trial', function () { return 'foo'; })
->run();
}
public function test_that_exceptions_are_swallowed_within_the_trial()
{
$r = (new Laboratory)
->experiment('test experiment')
->control(function () { return 'foo'; })
->trial('trial', function () { throw new Exception; })
->report();
$this->assertInstanceOf(Report::class, $r);
$this->assertNull($r->getControl()->getException());
$this->assertInstanceOf(Exception::class, $r->getTrial('trial')->getException());
}
public function test_that_control_and_trials_receive_parameters()
{
$r = (new Laboratory)
->experiment('test experiment')
->control(function ($one, $two) { return $one; })
->trial('trial', function ($one, $two) { return $two; })
->report('Panda', 'Giraffe');
$this->assertInstanceOf(Report::class, $r);
$this->assertEquals('Panda', $r->getControl()->getValue());
$this->assertEquals('Giraffe', $r->getTrial('trial')->getValue());
}
}