ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
DataSizeTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Daniel Weise <daniel.weise@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4require_once("./libs/composer/vendor/autoload.php");
5
7
14{
18 public function test_normal($a, $b, $expected)
19 {
20 $ds = new DataSize($a, $b);
21 $this->assertEquals($a/$b, $ds->getSize());
22 $this->assertEquals($b, $ds->getUnit());
23 $this->assertEquals($expected, $ds->__toString());
24 }
25
26 public function test_division_by_zero()
27 {
28 try {
29 $ds = new DataSize(4533, 0);
30 $this->assertFalse("This should not happen");
31 } catch (\Exception $e) {
32 $this->assertTrue(true);
33 }
34 }
35
36 public function tDataProvider()
37 {
38 return array(array(122, 1000, "0.122 KB"),
39 array(-122, 1000, "-0.122 KB"),
40 array(122, 1000000, "0.000122 MB"),
41 array(-122, 1000000, "-0.000122 MB"),
42 array(122, 1000000000, "1.22E-7 GB"),
43 array(-122, 1000000000, "-1.22E-7 GB"),
44 array(122, 1000000000000, "1.22E-10 TB"),
45 array(-122, 1000000000000, "-1.22E-10 TB"),
46 array(122, 1000000000000000, "1.22E-13 PB"),
47 array(-122, 1000000000000000, "-1.22E-13 PB"),
48 array(122, 1000000000000000000, "1.22E-16 EB"),
49 array(-122, 1000000000000000000, "-1.22E-16 EB"),
50
51 // This tests will fail because the second param of DataSize
52 // needs an integer and this numbers are to big.
53 // array(122, 1000000000000000000000, "1.22E-19 ZB"),
54 // array(-122, 1000000000000000000000, "-1.22E-19 ZB"),
55 // array(122, 1000000000000000000000000, "1.22E-19 YB"),
56 // array(-122, 1000000000000000000000000, "-1.22E-19 YB")
57
58 array(122, 1024, "0.119140625 KiB"),
59 array(-122, 1024, "-0.119140625 KiB"),
60 array(122, 1048576, "0.00011634826660156 MiB"),
61 array(-122, 1048576, "-0.00011634826660156 MiB"),
62 array(122, 1073741824, "1.1362135410309E-7 GiB"),
63 array(-122, 1073741824, "-1.1362135410309E-7 GiB"),
64 array(122, 1099511627776, "1.109583536163E-10 TiB"),
65 array(-122, 1099511627776, "-1.109583536163E-10 TiB"),
66 array(122, 1125899906842624, "1.0835776720342E-13 PiB"),
67 array(-122, 1125899906842624, "-1.0835776720342E-13 PiB"),
68 array(122, 1152921504606846976, "1.0581813203459E-16 EiB"),
69 array(-122, 1152921504606846976, "-1.0581813203459E-16 EiB")
70 );
71 }
72}
An exception for terminatinating execution or to throw for unit testing.
Testing the DataSize object.
test_normal($a, $b, $expected)
@dataProvider tDataProvider
Class DataSize.
Definition: DataSize.php:16