ILIAS  release_8 Revision v8.24
FloatTransformationTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
26
28{
30
31 protected function setUp(): void
32 {
33 $this->transformation = new FloatTransformation();
34 }
35
41 public function testFloatTransformation($originVal, float $expectedVal): void
42 {
43 $transformedValue = $this->transformation->transform($originVal);
44 $this->assertIsFloat($transformedValue);
45 $this->assertEquals($expectedVal, $transformedValue);
46 }
47
52 public function testFailingTransformations($failingVal): void
53 {
54 $this->expectNotToPerformAssertions();
55 try {
56 $transformedValue = $this->transformation->transform($failingVal);
57 } catch (ConstraintViolationException $exception) {
58 return;
59 }
60 $this->fail();
61 }
62
63 public function FailingTransformationDataProvider(): array
64 {
65 return [
66 'null' => [null],
67 'empty' => [""],
68 'written_false' => ['false'],
69 'written_null' => ['null'],
70 'NaN' => [NAN],
71 'written_NaN' => ['NaN'],
72 'INF' => [INF],
73 'neg_INF' => [-INF],
74 'written_INF' => ['INF'],
75 'written_neg_INF' => ['-INF'],
76 'octal_notation1' => ["01"],
77 'octal_notation2' => ["-01"],
78 'mill_delim' => ["1'000"],
79 'leading_dot' => [".5"],
80 'leading_comma' => [",661"]
81 ];
82 }
83
84 public function FloatTestDataProvider(): array
85 {
86 return [
87 'some_float' => [1.0, 1.0],
88 'pos_bool' => [true, 1.0],
89 'neg_bool' => [false, 0.0],
90 'string_comma' => ['234,23', 234.23],
91 'neg_string_comma' => ['-234,23', -234.23],
92 'neg_string_comma_trimming' => [' -234,23 ', -234.23],
93 'string_point' => ['234.23', 234.23],
94 'neg_string_point' => ['-234.23', -234.23],
95 'neg_string_point_trimming' => [' -234.23 ', -234.23],
96 'string_e_notation' => ['7E10', 70000000000],
97 'string_e_notation_trimming' => [' 7E10 ', 70000000000],
98 'neg_string_e_notation' => ['-7E10', -70000000000],
99 'neg_string_e_notation_trimming' => [' -7E10 ', -70000000000],
100 'int_val' => [23, 23.0],
101 'neg_int_val' => [-2, -2.0],
102 'zero_int' => [0, 0.0],
103 'zero_string' => ["0", 0.0],
104 'float_st_one' => [0.1, 0.1],
105 'floatstr_st_one' => ['0.1', 0.1],
106 'floatstr_st_one_negative' => ['-0.1', -0.1],
107 'floatstr_st_one_comma' => ['0,1', 0.1],
108 'floatstr_st_one_comma_negative' => ['-0,1', -0.1]
109 ];
110 }
111}
testFailingTransformations($failingVal)
@dataProvider FailingTransformationDataProvider
testFloatTransformation($originVal, float $expectedVal)
@dataProvider FloatTestDataProvider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...