ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
DatasetTest.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 
24 use ILIAS\Data;
28 
29 class DatasetTest extends TestCase
30 {
31  protected Data\Factory $f;
32 
33  protected function setUp(): void
34  {
35  $this->f = new Data\Factory();
36  }
37 
38  protected function getSimpleDimensions(): array
39  {
40  $c_dimension = $this->f->dimension()->cardinal();
41  $dimensions = ["A dimension" => $c_dimension, "Another dimension" => $c_dimension];
42 
43  return $dimensions;
44  }
45 
46  protected function getExtendedDimensions(): array
47  {
48  $c_dimension = $this->f->dimension()->cardinal();
49  $r_dimension = $this->f->dimension()->range($c_dimension);
50  $dimensions = [
51  "First dimension" => $c_dimension,
52  "Second dimension" => $c_dimension,
53  "Third dimension" => $r_dimension
54  ];
55 
56  return $dimensions;
57  }
58 
59  public function testDimensions(): void
60  {
61  try {
62  $dimensions = $this->getSimpleDimensions();
63  $dataset = $this->f->dataset($dimensions);
64  $this->assertEquals($dimensions, $dataset->getDimensions());
65  } catch (\InvalidArgumentException $e) {
66  $this->assertFalse("This should not happen.");
67  }
68  }
69 
70  public function testInvalidDimension(): void
71  {
72  try {
73  $dimension = "Dimension";
74  $dataset = $this->f->dataset(["A dimension" => $dimension]);
75  $this->assertFalse("This should not happen.");
76  } catch (\InvalidArgumentException $e) {
77  $this->assertTrue(true);
78  }
79  }
80 
81  public function testInvalidDimensionKey(): void
82  {
83  try {
84  $dimension = $this->f->dimension()->cardinal();
85  $dataset = $this->f->dataset([1 => $dimension]);
86  $this->assertFalse("This should not happen.");
87  } catch (\InvalidArgumentException $e) {
88  $this->assertTrue(true);
89  }
90  }
91 
92  public function testwithPoint(): void
93  {
94  $dataset = $this->f->dataset($this->getSimpleDimensions());
95  $points = ["A dimension" => 1, "Another dimension" => 2];
96  $dataset = $dataset->withPoint(
97  "Item",
98  $points
99  );
100  $this->assertEquals(["Item" => $points], $dataset->getPoints());
101  }
102 
103  public function testwithInvalidPointsCount(): void
104  {
105  try {
106  $dataset = $this->f->dataset($this->getSimpleDimensions());
107  $points = ["A dimension" => 1, "Second dimension" => 2];
108  $dataset = $dataset->withPoint(
109  "Item",
110  $points
111  );
112  $this->assertFalse("This should not happen.");
113  } catch (\ArgumentCountError $e) {
114  $this->assertTrue(true);
115  }
116  }
117 
118  public function testwithAlternativeInformation(): void
119  {
120  $dataset = $this->f->dataset($this->getSimpleDimensions());
121  $info = ["A dimension" => "An information", "Another dimension" => null];
122  $dataset = $dataset->withAlternativeInformation(
123  "Item",
124  $info
125  );
126  $this->assertEquals(["Item" => $info], $dataset->getAlternativeInformation());
127  }
128 
130  {
131  try {
132  $dataset = $this->f->dataset($this->getSimpleDimensions());
133  $info = ["A dimension" => "An information", "Second dimension" => null];
134  $dataset = $dataset->withAlternativeInformation(
135  "Item",
136  $info
137  );
138  $this->assertFalse("This should not happen.");
139  } catch (\ArgumentCountError $e) {
140  $this->assertTrue(true);
141  }
142  }
143 
145  {
146  try {
147  $dataset = $this->f->dataset($this->getSimpleDimensions());
148  $info = ["A dimension" => "An information", "Another dimension" => 1];
149  $dataset = $dataset->withAlternativeInformation(
150  "Item",
151  $info
152  );
153  $this->assertFalse("This should not happen.");
154  } catch (\InvalidArgumentException $e) {
155  $this->assertTrue(true);
156  }
157  }
158 
159  public function testwithResetDataset(): void
160  {
161  $dataset = $this->f->dataset($this->getSimpleDimensions());
162  $points = ["A dimension" => 1, "Another dimension" => 2];
163  $info = ["A dimension" => "An information", "Another dimension" => null];
164  $dataset = $dataset->withPoint(
165  "Item",
166  $points
167  );
168  $dataset = $dataset->withAlternativeInformation(
169  "Item",
170  $info
171  );
172 
173  $this->assertEquals(false, $dataset->isEmpty());
174 
175  $dataset = $dataset->withResetDataset();
176 
177  $this->assertEquals(true, $dataset->isEmpty());
178  $this->assertEquals([], $dataset->getPoints());
179  $this->assertEquals([], $dataset->getAlternativeInformation());
180  }
181 
182  public function testMinValue(): void
183  {
184  $dataset = $this->f->dataset($this->getExtendedDimensions());
185  $points1 = ["First dimension" => 0, "Second dimension" => 0.5, "Third dimension" => [0, 1]];
186  $points2 = ["First dimension" => -3, "Second dimension" => 5, "Third dimension" => [-4, -1.5]];
187  $points3 = ["First dimension" => -2, "Second dimension" => 5, "Third dimension" => [-3, -1.5]];
188  $dataset = $dataset->withPoint(
189  "Item 1",
190  $points1
191  );
192  $dataset = $dataset->withPoint(
193  "Item 2",
194  $points2
195  );
196  $dataset = $dataset->withPoint(
197  "Item 2",
198  $points3
199  );
200  $this->assertEquals(-2, $dataset->getMinValueForDimension("First dimension"));
201  $this->assertEquals(0.5, $dataset->getMinValueForDimension("Second dimension"));
202  $this->assertEquals(-3, $dataset->getMinValueForDimension("Third dimension"));
203  }
204 
205  public function testMaxValue(): void
206  {
207  $dataset = $this->f->dataset($this->getExtendedDimensions());
208  $points1 = ["First dimension" => 0, "Second dimension" => -0.5, "Third dimension" => [0, 1]];
209  $points2 = ["First dimension" => -3, "Second dimension" => -5, "Third dimension" => [-4, 1.5]];
210  $dataset = $dataset->withPoint(
211  "Item 1",
212  $points1
213  );
214  $dataset = $dataset->withPoint(
215  "Item 2",
216  $points2
217  );
218  $this->assertEquals(0, $dataset->getMaxValueForDimension("First dimension"));
219  $this->assertEquals(-0.5, $dataset->getMaxValueForDimension("Second dimension"));
220  $this->assertEquals(1.5, $dataset->getMaxValueForDimension("Third dimension"));
221  }
222 }
Data Factory $f
Definition: DatasetTest.php:31
getExtendedDimensions()
Definition: DatasetTest.php:46
testInvalidDimensionKey()
Definition: DatasetTest.php:81
testwithInvalidAlternativeInformationCount()
testwithInvalidAlternativeInformationValue()
testInvalidDimension()
Definition: DatasetTest.php:70
testwithInvalidPointsCount()
testwithAlternativeInformation()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Dataset.php:22
getSimpleDimensions()
Definition: DatasetTest.php:38
testwithResetDataset()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...