ILIAS  release_7 Revision v7.30-3-g800a261c036
FloatTransformationTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2020 Luka K. A. Stocker, Extended GPL, see docs/LICENSE */
4
6
7require_once('./libs/composer/vendor/autoload.php');
8
12
17{
19
20 public function setUp() : void
21 {
22 $this->transformation = new FloatTransformation();
23 }
24
30 public function testFloatTransformation($originVal, $expectedVal)
31 {
32 $transformedValue = $this->transformation->transform($originVal);
33 $this->assertIsFloat($transformedValue);
34 $this->assertEquals($expectedVal, $transformedValue);
35 }
36
41 public function testFailingTransformations($failingVal)
42 {
43 $this->expectNotToPerformAssertions();
44 try {
45 $transformedValue = $this->transformation->transform($failingVal);
46 } catch (ConstraintViolationException $exception) {
47 return;
48 }
49 $this->fail();
50 }
51
53 {
54 return [
55 'null' => [null],
56 'empty' => [""],
57 'written_false' => ['false'],
58 'written_null' => ['null'],
59 'NaN' => [NAN],
60 'written_NaN' => ['NaN'],
61 'INF' => [INF],
62 'neg_INF' => [-INF],
63 'written_INF' => ['INF'],
64 'written_neg_INF' => ['-INF'],
65 'octal_notation1' => ["01"],
66 'octal_notation2' => ["-01"],
67 'mill_delim' => ["1'000"],
68 'leading_dot' => [".5"],
69 'leading_comma' => [",661"]
70 ];
71 }
72
73 public function FloatTestDataProvider()
74 {
75 return [
76 'some_float' => [1.0, 1.0],
77 'pos_bool' => [true, 1.0],
78 'neg_bool' => [false, 0.0],
79 'string_comma' => ['234,23', 234.23],
80 'neg_string_comma' => ['-234,23', -234.23],
81 'neg_string_comma_trimming' => [' -234,23 ', -234.23],
82 'string_point' => ['234.23', 234.23],
83 'neg_string_point' => ['-234.23', -234.23],
84 'neg_string_point_trimming' => [' -234.23 ', -234.23],
85 'string_e_notation' => ['7E10', 70000000000],
86 'string_e_notation_trimming' => [' 7E10 ', 70000000000],
87 'neg_string_e_notation' => ['-7E10', -70000000000],
88 'neg_string_e_notation_trimming' => [' -7E10 ', -70000000000],
89 'int_val' => [23, 23.0],
90 'neg_int_val' => [-2, -2.0],
91 'zero_int' => [0, 0.0],
92 'zero_string' => ["0", 0.0],
93 'float_st_one' => [0.1, 0.1],
94 'floatstr_st_one' => ['0.1', 0.1],
95 'floatstr_st_one_negative' => ['-0.1', -0.1],
96 'floatstr_st_one_comma' => ['0,1', 0.1],
97 'floatstr_st_one_comma_negative' => ['-0,1', -0.1]
98 ];
99 }
100}
An exception for terminatinating execution or to throw for unit testing.
testFloatTransformation($originVal, $expectedVal)
@dataProvider FloatTestDataProvider
testFailingTransformations($failingVal)
@dataProvider FailingTransformationDataProvider