This repository was archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathphp.yml
More file actions
118 lines (116 loc) · 3.58 KB
/
Copy pathphp.yml
File metadata and controls
118 lines (116 loc) · 3.58 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
cw-2:
bug fixes:
initial: |-
multiply(a, b) {
a * b
}
answer: |-
function multiply($a, $b) {
return $a * $b;
}
fixture: |-
$test->describe("The 'multiply' function", function () {
global $test;
$test->it("should pass all the tests provided", function () {
global $test;
$test->assert_equals(multiply(1, 1), 1);
$test->assert_equals(multiply(2, 3), 6);
$test->assert_equals(multiply(3, 2), 6);
$test->assert_equals(multiply(3, 5), 15);
$test->assert_equals(multiply(5, 3), 15);
$test->assert_equals(multiply(4, 7), 28);
$test->assert_equals(multiply(7, 4), 28);
});
});
algorithms:
initial: |-
// return the two oldest/oldest ages within the array of ages passed in.
// it should return the two ages as a sorted array, youngest age first
function twoOldestAges(ages){
}
answer: |-
function twoOldestAges($ages){
$oldest = 0;
$nextOldest;
for($i = 0; $i < count($ages); $i++){
$age = $ages[$i];
if ($age > $oldest){
$nextOldest = $oldest;
$oldest = $age;
}
elseif ($age > $nextOldest){
$nextOldest = $age;
}
}
return [$nextOldest, $oldest];
}
fixture: |-
$test->describe("The 'twoOldestAges' function", function () {
global $test;
$test->it("should pass all the tests provided", function () {
global $test;
$results1 = twoOldestAges([1, 5, 87, 45, 8, 8]);
$test->assert_equals($results1[0], 45);
$test->assert_equals($results1[1], 87);
$results2 = twoOldestAges([6, 5, 83, 5, 3, 18]);
$test->assert_similar($results2, [18, 83]);
});
});
phpunit:
bug fixes:
initial: |-
multiply(a, b) {
a * b
}
answer: |-
function multiply($a, $b) {
return $a * $b;
}
fixture: |-
class MultiplyFunction extends TestCase
{
public function testMultiply() {
$this->assertEquals(multiply(1, 1), 1);
$this->assertEquals(multiply(2, 3), 6);
$this->assertEquals(multiply(3, 2), 6);
}
public function testMultiplyExtra() {
$this->assertEquals(multiply(3, 5), 15);
$this->assertEquals(multiply(5, 3), 15);
$this->assertEquals(multiply(4, 7), 28);
$this->assertEquals(multiply(7, 4), 28);
}
}
algorithms:
initial: |-
// return the two oldest/oldest ages within the array of ages passed in.
// it should return the two ages as a sorted array, youngest age first
function twoOldestAges(ages){
}
answer: |-
function twoOldestAges($ages){
$oldest = 0;
$nextOldest;
for($i = 0; $i < count($ages); $i++){
$age = $ages[$i];
if ($age > $oldest){
$nextOldest = $oldest;
$oldest = $age;
}
elseif ($age > $nextOldest){
$nextOldest = $age;
}
}
return [$nextOldest, $oldest];
}
fixture: |-
class TwoOldestAgesFunction extends TestCase
{
public function testAlgorithm() {
$results1 = twoOldestAges([1, 5, 87, 45, 8, 8]);
$this->assertEquals($results1[0], 45);
$this->assertEquals($results1[1], 87);
$results2 = twoOldestAges([6, 5, 83, 5, 3, 18]);
$this->assertEquals($results2, [18, 83]);
}
}