math_expression_stack.test
1.79 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
<?php
/**
* @file
* Contains \CtoolsMathExpressionStackTestCase
*/
/**
* Tests the simple MathExpressionStack class.
*/
class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'CTools math expression stack tests',
'description' => 'Test the stack class of the math expression library.',
'group' => 'Chaos Tools Suite',
);
}
public function setUp() {
parent::setUp('ctools', 'ctools_plugin_test');
}
public function testStack() {
$stack = new ctools_math_expr_stack();
// Test the empty stack.
$this->assertNull($stack->last());
$this->assertNull($stack->pop());
// Add an element and see whether it's the right element.
$value = $this->randomName();
$stack->push($value);
$this->assertIdentical($value, $stack->last());
$this->assertIdentical($value, $stack->pop());
$this->assertNull($stack->pop());
// Add multiple elements and see whether they are returned in the right order.
$values = array($this->randomName(), $this->randomName(), $this->randomName());
foreach ($values as $value) {
$stack->push($value);
}
// Test the different elements at different positions with the last() method.
$count = count($values);
foreach ($values as $key => $value) {
$this->assertEqual($value, $stack->last($count - $key));
}
// Pass in a non-valid number to last.
$non_valid_number = rand(10, 20);
$this->assertNull($stack->last($non_valid_number));
// Test the order of the poping.
$values = array_reverse($values);
foreach ($values as $key => $value) {
$this->assertEqual($stack->last(), $value);
$this->assertEqual($stack->pop(), $value);
}
$this->assertNull($stack->pop());
}
}