ILIAS  release_7 Revision v7.30-3-g800a261c036
RangeTest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4use PHPUnit\Framework\TestCase;
5
9class RangeTest extends TestCase
10{
11 public function testFactory()
12 {
13 $f = new ILIAS\Data\Factory();
14 $range = $f->range(1, 2);
15 $this->assertInstanceOf(Range::class, $range);
16 return $range;
17 }
18
22 public function testValues(Range $range)
23 {
24 $this->assertEquals(1, $range->getStart());
25 $this->assertEquals(2, $range->getLength());
26 }
27
31 public function testEndCalculation(Range $range)
32 {
33 $this->assertEquals(3, $range->getEnd());
34 }
35
39 public function testWithLength(Range $range)
40 {
41 $range = $range->withLength(3);
42 $this->assertEquals(1, $range->getStart());
43 $this->assertEquals(3, $range->getLength());
44 $this->assertEquals(4, $range->getEnd());
45 return $range;
46 }
47
51 public function testWithStart(Range $range)
52 {
53 $range = $range->withStart(3);
54 $this->assertEquals(3, $range->getStart());
55 $this->assertEquals(3, $range->getLength());
56 $this->assertEquals(6, $range->getEnd());
57 return $range;
58 }
59
63 public function testUnpack(Range $range)
64 {
65 $this->assertEquals(
66 [3,3],
67 $range->unpack()
68 );
69 }
70
74 public function testNegativeStart(Range $range)
75 {
76 $this->expectException(InvalidArgumentException::class);
77 $range = $range->withStart(-5);
78 }
79
83 public function testNegativeLength(Range $range)
84 {
85 $this->expectException(InvalidArgumentException::class);
86 $range = $range->withLength(-1);
87 }
88
92 public function testNullLength(Range $range)
93 {
94 $this->expectException(InvalidArgumentException::class);
95 $range = $range->withLength(0);
96 }
97
99 {
100 $this->expectException(InvalidArgumentException::class);
101 $f = new ILIAS\Data\Factory();
102 $range = $f->range(-1, 2);
103 }
104
106 {
107 $this->expectException(InvalidArgumentException::class);
108 $f = new ILIAS\Data\Factory();
109 $range = $f->range(1, -2);
110 }
111
113 {
114 $this->expectException(InvalidArgumentException::class);
115 $f = new ILIAS\Data\Factory();
116 $range = $f->range(1, 0);
117 }
118}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:11
withLength(int $length)
Definition: Range.php:73
withStart(int $start)
Definition: Range.php:65
testConstructionWrongLength()
Definition: RangeTest.php:105
testUnpack(Range $range)
@depends testWithStart
Definition: RangeTest.php:63
testConstructionWrongStart()
Definition: RangeTest.php:98
testConstructionNullLength()
Definition: RangeTest.php:112
testWithLength(Range $range)
@depends testFactory
Definition: RangeTest.php:39
testNullLength(Range $range)
@depends testFactory
Definition: RangeTest.php:92
testFactory()
Definition: RangeTest.php:11
testNegativeLength(Range $range)
@depends testFactory
Definition: RangeTest.php:83
testWithStart(Range $range)
@depends testWithLength
Definition: RangeTest.php:51
testNegativeStart(Range $range)
@depends testFactory
Definition: RangeTest.php:74
testEndCalculation(Range $range)
@depends testFactory
Definition: RangeTest.php:31
testValues(Range $range)
@depends testFactory
Definition: RangeTest.php:22