ILIAS  release_7 Revision v7.30-3-g800a261c036
DataSizeTest Class Reference

Testing the DataSize object. More...

+ Inheritance diagram for DataSizeTest:
+ Collaboration diagram for DataSizeTest:

Public Member Functions

 test_normal ($a, $b, $expected, $expected_in_bytes)
 @dataProvider tDataProvider More...
 
 test_division_by_zero ()
 
 tDataProvider ()
 

Detailed Description

Member Function Documentation

◆ tDataProvider()

DataSizeTest::tDataProvider ( )

Definition at line 40 of file DataSizeTest.php.

41 {
42 return [
43 [122, 1000, "0.122 KB", 122],
44 [-122, 1000, "-0.122 KB", -122],
45 [122, 1000000, "0.000122 MB", 122],
46 [-122, 1000000, "-0.000122 MB", -122],
47 [122, 1000000000, "1.22E-7 GB", 122],
48 [-122, 1000000000, "-1.22E-7 GB", -122],
49 [122, 1000000000000, "1.22E-10 TB", null], // There is a float rounding error here
50 [-122, 1000000000000, "-1.22E-10 TB", null], // There is a float rounding error here
51 [122, 1000000000000000, "1.22E-13 PB", 122],
52 [-122, 1000000000000000, "-1.22E-13 PB", -122],
53 [122, 1000000000000000000, "1.22E-16 EB", 122],
54 [-122, 1000000000000000000, "-1.22E-16 EB", -122],
55 [122, 1024, "0.119140625 KiB", 122],
56 [-122, 1024, "-0.119140625 KiB", -122],
57 [122, 1048576, "0.00011634826660156 MiB", 122],
58 [-122, 1048576, "-0.00011634826660156 MiB", -122],
59 [122, 1073741824, "1.1362135410309E-7 GiB", 122],
60 [-122, 1073741824, "-1.1362135410309E-7 GiB", -122],
61 [122, 1099511627776, "1.109583536163E-10 TiB", 122],
62 [-122, 1099511627776, "-1.109583536163E-10 TiB", -122],
63 [122, 1125899906842624, "1.0835776720342E-13 PiB", 122],
64 [-122, 1125899906842624, "-1.0835776720342E-13 PiB", -122],
65 [122, 1152921504606846976, "1.0581813203459E-16 EiB", 122],
66 [-122, 1152921504606846976, "-1.0581813203459E-16 EiB", -122],
67 [10 * DataSize::KiB, DataSize::KiB, "10 KiB", 10 * DataSize::KiB]
68
69 // This tests will fail because the second param of DataSize
70 // needs an integer and this numbers are to big.
71 // [122, 1000000000000000000000, "1.22E-19 ZB"],
72 // [-122, 1000000000000000000000, "-1.22E-19 ZB"],
73 // [122, 1000000000000000000000000, "1.22E-19 YB"],
74 // [-122, 1000000000000000000000000, "-1.22E-19 YB"]
75 ];
76 }

◆ test_division_by_zero()

DataSizeTest::test_division_by_zero ( )

Definition at line 30 of file DataSizeTest.php.

31 {
32 try {
33 $ds = new DataSize(4533, 0);
34 $this->assertFalse("This should not happen");
35 } catch (\Exception $e) {
36 $this->assertTrue(true);
37 }
38 }
Class DataSize.
Definition: DataSize.php:16

References Vendor\Package\$e.

◆ test_normal()

DataSizeTest::test_normal (   $a,
  $b,
  $expected,
  $expected_in_bytes 
)

@dataProvider tDataProvider

Definition at line 19 of file DataSizeTest.php.

20 {
21 $ds = new DataSize($a, $b);
22 $this->assertEquals($a / $b, $ds->getSize());
23 $this->assertEquals($b, $ds->getUnit());
24 $this->assertEquals($expected, $ds->__toString());
25 if ($expected_in_bytes) {
26 $this->assertEquals($expected_in_bytes, $ds->inBytes());
27 }
28 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, and Vendor\Package\$b.


The documentation for this class was generated from the following file: