ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
DimensionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 require_once('./libs/composer/vendor/autoload.php');
23 
26 
27 class DimensionTest extends TestCase
28 {
29  protected Dimension\Factory $f;
30 
31  protected function setUp(): void
32  {
33  $this->f = new Dimension\Factory();
34  }
35 
36  public function testCardinaltLabels(): void
37  {
38  $labels = ["label1", "label2", "label3"];
39  $c = $this->f->cardinal($labels);
40  $this->assertEquals($labels, $c->getLabels());
41  }
42 
43  public function testRangeLabels(): void
44  {
45  $labels = ["label1", "label2", "label3"];
46  $c = $this->f->cardinal($labels);
47  $r = $this->f->range($c);
48  $this->assertEquals($labels, $r->getLabels());
49  $this->assertEquals($c->getLabels(), $r->getLabels());
50  }
51 
52  public function testCardinalNumericValues(): void
53  {
54  try {
55  $c = $this->f->cardinal();
56  $c->checkValue(-2);
57  $c->checkValue(0);
58  $c->checkValue(0.5);
59  $c->checkValue("1.5");
60  $this->assertTrue(true);
61  } catch (\InvalidArgumentException $e) {
62  $this->assertFalse("This should not happen.");
63  }
64  }
65 
66  public function testCardinalNullValue(): void
67  {
68  try {
69  $c = $this->f->cardinal();
70  $c->checkValue(null);
71  $this->assertTrue(true);
72  } catch (\InvalidArgumentException $e) {
73  $this->assertFalse("This should not happen.");
74  }
75  }
76 
77  public function testCardinalInvalidValue(): void
78  {
79  try {
80  $c = $this->f->cardinal();
81  $c->checkValue("A value");
82  $this->assertFalse("This should not happen.");
83  } catch (\InvalidArgumentException $e) {
84  $this->assertTrue(true);
85  }
86  }
87 
88  public function testRangeNullValue(): void
89  {
90  try {
91  $c = $this->f->cardinal();
92  $r = $this->f->range($c);
93  $r->checkValue(null);
94  $this->assertTrue(true);
95  } catch (\InvalidArgumentException $e) {
96  $this->assertFalse("This should not happen.");
97  }
98  }
99 
100  public function testRangeNumericValues(): void
101  {
102  try {
103  $c = $this->f->cardinal();
104  $r = $this->f->range($c);
105  $r->checkValue([-2, 0]);
106  $r->checkValue([0.5, "1.5"]);
107  $this->assertTrue(true);
108  } catch (\InvalidArgumentException $e) {
109  $this->assertFalse("This should not happen.");
110  }
111  }
112 
113  public function testRangeInvalidArray(): void
114  {
115  try {
116  $c = $this->f->cardinal();
117  $r = $this->f->range($c);
118  $r->checkValue(2);
119  $this->assertFalse("This should not happen.");
120  } catch (\InvalidArgumentException $e) {
121  $this->assertTrue(true);
122  }
123  }
124 
125  public function testRangeInvalidCount(): void
126  {
127  try {
128  $c = $this->f->cardinal();
129  $r = $this->f->range($c);
130  $r->checkValue([2]);
131  $this->assertFalse("This should not happen.");
132  } catch (\InvalidArgumentException $e) {
133  $this->assertTrue(true);
134  }
135  }
136 
137  public function testRangeInvalidValues(): void
138  {
139  try {
140  $c = $this->f->cardinal();
141  $r = $this->f->range($c);
142  $r->checkValue([2, "A value"]);
143  $this->assertFalse("This should not happen.");
144  } catch (\InvalidArgumentException $e) {
145  $this->assertTrue(true);
146  }
147  }
148 }
Dimension Factory $f
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$r