forked from orlandophp/04-Roman-Numerals
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RomanNumeralTest.php
114 lines (102 loc) · 3.37 KB
/
RomanNumeralTest.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
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
<?php
require_once 'PHPUnit/Framework.php';
require_once 'RomanNumeral.php';
class MainTest
extends PHPUnit_Framework_TestCase
{
public function provide_numerals ( )
{
return array(
array( 0, 'N' ),
array( 1, 'I' ),
array( 2, 'II' ),
array( 3, 'III' ),
array( 4, 'IIII' ),
array( 4, 'IV' ),
array( 5, 'V'),
array( 6, 'VI'),
array( 7, 'VII'),
array( 8, 'VIII'),
array( 9, 'VIIII'),
array( 9, 'IX' ),
array( 10, 'X'),
array( 20, 'XX'),
array( 40, 'XL'),
array( 49, 'XLIX'),
array( 50, 'L'),
array( 100, 'C'),
array( 500, 'D'),
array( 1000, 'M'),
array( 1234, 'MCCXXXIV' ),
); // END datasets
}
public function provide_decimals(){
return array(
array( 'N', 0 ),
array( 'I', 1 ),
array( 'II', 2 ),
array( 'III', 3 ),
array( 'IV', 4 ),
array( 'V', 5 ),
array( 'IX', 9 ),
array( 'X', 10 ),
array( 'XI', 11 ),
array( 'XII', 12 ),
array( 'XIV', 14 ),
array( 'XIX', 19 ),
array( 'XXX', 30 ),
array( 'XL', 40 ),
array( 'L', 50 ),
array( 'C', 100 ),
array( 'D', 500 ),
array( 'M', 1000 ),
array( 'MCCXXXIV', 1234 ),
array( 'MMMCMXCIX', 3999 ),
);
} //END provide_decimals
public function provide_parsables(){
return array(
array(array('I'), 'I'),
array(array('I', 'I'), 'II'),
array(array('I', 'I', 'I'), 'III'),
array(array('I', 'I', 'I', 'I'), 'IIII'),
array(array('V'), 'V'),
);
}
public function setup(){
$this->fixture = new RomanNumeral();
$this->assertTrue( ($this->fixture instanceof RomanNumeral), 'This is not a roman numeral' );
} //END setup
/**
* @dataProvider provide_parsables
* @param integer $expected
* @param string $numeral
*/
public function test_parse( $expected, $RomanNumeral ){
$this->assertEquals($expected, $this->fixture->parseRoman( $RomanNumeral ));
}
/**
* @dataProvider provide_numerals
* @param integer $expected
* @param string $romanNumeral
*/
public function test_toInt( $expected, $romanNumeral ) {
$this->assertEquals($expected, $this->fixture->toInt( $romanNumeral ) );
}
/**
* @dataProvider provide_decimals
* @param string $expected
* @param integer $integer
*/
public function test_fromInt( $expected, $integer ){
$this->assertEquals( $expected, $this->fixture->fromInt( $integer ) );
} //END test_fromDecimal
public function test_instantiation(){
$object = new RomanNumeral();
$object->toInt('CLM');
$this->assertTrue( ( $object instanceof RomanNumeral ), 'This is not a roman numeral' );
$object = new RomanNumeral();
$object->fromInt(495);
$this->assertTrue( ( $object instanceof RomanNumeral ), 'This is not a roman numeral' );
}
} // END RomanNumeralTest