ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ClosedFloatIntervalTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8namespace ILIAS\Data;
9
12use PHPUnit\Framework\TestCase;
13
14require_once 'libs/composer/vendor/autoload.php';
15
16class ClosedFloatIntervalTest extends TestCase
17{
21 public function testValidFloatRanges()
22 {
23 $floatRange = new ClosedFloatInterval(3.0, 100.4);
24
25 $this->assertSame($floatRange->minimum(), 3.0);
26 $this->assertSame($floatRange->maximum(), 100.4);
27 }
28
29 public function testValueIsInRange()
30 {
31 $range = new ClosedFloatInterval(3.0, 100.4);
32
33 $this->assertTrue($range->spans(50));
34 }
35
37 {
38 $range = new ClosedFloatInterval(3.0, 100.4);
39
40 $this->assertFalse($range->spans(3));
41 }
42
44 {
45 $range = new ClosedFloatInterval(3.0, 100.4);
46
47 $this->assertFalse($range->spans(3));
48 }
49
51 {
52 $range = new ClosedFloatInterval(3.0, 100.4);
53
54 $this->assertFalse($range->spans(1));
55 }
56
58 {
59 $range = new ClosedFloatInterval(3.0, 100.4);
60
61 $this->assertFalse($range->spans(101));
62 }
63
67 public function testHexIsAllowForRanges()
68 {
69 $floatRange = new ClosedFloatInterval(0x3, 0xA);
70
71 $this->assertSame($floatRange->minimum(), 3.0);
72 $this->assertSame($floatRange->maximum(), 10.0);
73 }
74
79 {
80 $floatRange = new ClosedFloatInterval(0b11, 0b1010);
81
82 $this->assertSame($floatRange->minimum(), 3.0);
83 $this->assertSame($floatRange->maximum(), 10.0);
84 }
85
87 {
88 $this->expectNotToPerformAssertions();
89
90 try {
91 $floatRange = new ClosedFloatInterval(3.0, 3.0);
92 } catch (ConstraintViolationException $exception) {
93 return;
94 }
95 $this->fail();
96 }
97
99 {
100 $this->expectNotToPerformAssertions();
101
102 try {
103 $floatRange = new ClosedFloatInterval(3.0, 1.0);
104 } catch (ConstraintViolationException $exception) {
105 return;
106 }
107 $this->fail();
108 }
109}
An exception for terminatinating execution or to throw for unit testing.