ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DatasetTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once('./vendor/composer/vendor/autoload.php');
22
23use ILIAS\Data;
24use PHPUnit\Framework\TestCase;
25
26class DatasetTest extends TestCase
27{
28 protected Data\Factory $f;
29
30 protected function setUp(): void
31 {
32 $this->f = new Data\Factory();
33 }
34
35 protected function getSimpleDimensions(): array
36 {
37 $c_dimension = $this->f->dimension()->cardinal();
38 $dimensions = ["A dimension" => $c_dimension, "Another dimension" => $c_dimension];
39
40 return $dimensions;
41 }
42
43 protected function getSimpleDimensionGroups(): array
44 {
45 $group = $this->f->dimension()->group("A dimension", "Another dimension");
46 $groups = ["A group" => $group, "Another group" => $group];
47
48 return $groups;
49 }
50
51 protected function getExtendedDimensions(): array
52 {
53 $c_dimension = $this->f->dimension()->cardinal();
54 $r_dimension = $this->f->dimension()->range($c_dimension);
55 $dimensions = [
56 "First dimension" => $c_dimension,
57 "Second dimension" => $c_dimension,
58 "Third dimension" => $r_dimension
59 ];
60
61 return $dimensions;
62 }
63
64 public function testDimensions(): void
65 {
66 try {
67 $dimensions = $this->getSimpleDimensions();
68 $dataset = $this->f->dataset($dimensions);
69 $this->assertEquals($dimensions, $dataset->getDimensions());
70 } catch (\InvalidArgumentException $e) {
71 $this->assertFalse("This should not happen.");
72 }
73 }
74
75 public function testInvalidDimension(): void
76 {
77 try {
78 $dimension = "Dimension";
79 $dataset = $this->f->dataset(["A dimension" => $dimension]);
80 $this->assertFalse("This should not happen.");
81 } catch (\InvalidArgumentException $e) {
82 $this->assertTrue(true);
83 }
84 }
85
86 public function testInvalidDimensionKey(): void
87 {
88 try {
89 $dimension = $this->f->dimension()->cardinal();
90 $dataset = $this->f->dataset([1 => $dimension]);
91 $this->assertFalse("This should not happen.");
92 } catch (\InvalidArgumentException $e) {
93 $this->assertTrue(true);
94 }
95 }
96
97 public function testwithPoint(): void
98 {
99 $dataset = $this->f->dataset($this->getSimpleDimensions());
100 $points = ["A dimension" => 1, "Another dimension" => 2];
101 $dataset = $dataset->withPoint(
102 "Item",
103 $points
104 );
105 $this->assertEquals(["Item" => $points], $dataset->getPoints());
106 }
107
108 public function testwithInvalidPointsCount(): void
109 {
110 try {
111 $dataset = $this->f->dataset($this->getSimpleDimensions());
112 $points = ["A dimension" => 1, "Second dimension" => 2];
113 $dataset = $dataset->withPoint(
114 "Item",
115 $points
116 );
117 $this->assertFalse("This should not happen.");
118 } catch (\ArgumentCountError $e) {
119 $this->assertTrue(true);
120 }
121 }
122
123 public function testwithAlternativeInformation(): void
124 {
125 $dataset = $this->f->dataset($this->getSimpleDimensions());
126 $info = ["A dimension" => "An information", "Another dimension" => null];
127 $dataset = $dataset->withAlternativeInformation(
128 "Item",
129 $info
130 );
131 $this->assertEquals(["Item" => $info], $dataset->getAlternativeInformation());
132 }
133
135 {
136 try {
137 $dataset = $this->f->dataset($this->getSimpleDimensions());
138 $info = ["A dimension" => "An information", "Second dimension" => null];
139 $dataset = $dataset->withAlternativeInformation(
140 "Item",
141 $info
142 );
143 $this->assertFalse("This should not happen.");
144 } catch (\ArgumentCountError $e) {
145 $this->assertTrue(true);
146 }
147 }
148
150 {
151 try {
152 $dataset = $this->f->dataset($this->getSimpleDimensions());
153 $info = ["A dimension" => "An information", "Another dimension" => 1];
154 $dataset = $dataset->withAlternativeInformation(
155 "Item",
156 $info
157 );
158 $this->assertFalse("This should not happen.");
159 } catch (\InvalidArgumentException $e) {
160 $this->assertTrue(true);
161 }
162 }
163
164 public function testwithResetDataset(): void
165 {
166 $dataset = $this->f->dataset($this->getSimpleDimensions());
167 $points = ["A dimension" => 1, "Another dimension" => 2];
168 $info = ["A dimension" => "An information", "Another dimension" => null];
169 $dataset = $dataset->withPoint(
170 "Item",
171 $points
172 );
173 $dataset = $dataset->withAlternativeInformation(
174 "Item",
175 $info
176 );
177
178 $this->assertEquals(false, $dataset->isEmpty());
179
180 $dataset = $dataset->withResetDataset();
181
182 $this->assertEquals(true, $dataset->isEmpty());
183 $this->assertEquals([], $dataset->getPoints());
184 $this->assertEquals([], $dataset->getAlternativeInformation());
185 }
186
187 public function testMinValue(): void
188 {
189 $dataset = $this->f->dataset($this->getExtendedDimensions());
190 $points1 = ["First dimension" => 0, "Second dimension" => 0.5, "Third dimension" => [0, 1]];
191 $points2 = ["First dimension" => -3, "Second dimension" => 5, "Third dimension" => [-4, -1.5]];
192 $points3 = ["First dimension" => -2, "Second dimension" => 5, "Third dimension" => [-3, -1.5]];
193 $dataset = $dataset->withPoint(
194 "Item 1",
195 $points1
196 );
197 $dataset = $dataset->withPoint(
198 "Item 2",
199 $points2
200 );
201 $dataset = $dataset->withPoint(
202 "Item 2",
203 $points3
204 );
205 $this->assertEquals(-2, $dataset->getMinValueForDimension("First dimension"));
206 $this->assertEquals(0.5, $dataset->getMinValueForDimension("Second dimension"));
207 $this->assertEquals(-3, $dataset->getMinValueForDimension("Third dimension"));
208 }
209
210 public function testMaxValue(): void
211 {
212 $dataset = $this->f->dataset($this->getExtendedDimensions());
213 $points1 = ["First dimension" => 0, "Second dimension" => -0.5, "Third dimension" => [0, 1]];
214 $points2 = ["First dimension" => -3, "Second dimension" => -5, "Third dimension" => [-4, 1.5]];
215 $dataset = $dataset->withPoint(
216 "Item 1",
217 $points1
218 );
219 $dataset = $dataset->withPoint(
220 "Item 2",
221 $points2
222 );
223 $this->assertEquals(0, $dataset->getMaxValueForDimension("First dimension"));
224 $this->assertEquals(-0.5, $dataset->getMaxValueForDimension("Second dimension"));
225 $this->assertEquals(1.5, $dataset->getMaxValueForDimension("Third dimension"));
226 }
227
228 public function testDimensionsWithGroups(): void
229 {
230 try {
231 $dimensions = $this->getSimpleDimensions();
232 $groups = $this->getSimpleDimensionGroups();
233 $dataset = $this->f->dataset($dimensions, $groups);
234 $this->assertEquals($groups, $dataset->getDimensionGroups());
235 } catch (\InvalidArgumentException $e) {
236 $this->fail("This should not happen.");
237 }
238 }
239
240 public function testInvalidDimensionGroup(): void
241 {
242 $dimensions = $this->getSimpleDimensions();
243 $group = "Group";
244
245 $this->expectException(\InvalidArgumentException::class);
246 $dataset = $this->f->dataset($dimensions, ["A group" => $group]);
247 }
248
249 public function testInvalidDimensionGroupKey(): void
250 {
251 $dimensions = $this->getSimpleDimensions();
252 $group = $this->f->dimension()->group("A dimension");
253
254 $this->expectException(\InvalidArgumentException::class);
255 $dataset = $this->f->dataset($dimensions, [1 => $group]);
256 }
257}
testInvalidDimensionGroupKey()
testwithInvalidAlternativeInformationValue()
testwithAlternativeInformation()
testInvalidDimensionGroup()
testwithInvalidPointsCount()
testwithInvalidAlternativeInformationCount()
testInvalidDimensionKey()
Definition: DatasetTest.php:86
getExtendedDimensions()
Definition: DatasetTest.php:51
testDimensionsWithGroups()
getSimpleDimensionGroups()
Definition: DatasetTest.php:43
Data Factory $f
Definition: DatasetTest.php:28
testwithResetDataset()
getSimpleDimensions()
Definition: DatasetTest.php:35
testInvalidDimension()
Definition: DatasetTest.php:75
$info
Definition: entry_point.php:21