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