| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | export component TestCase { |
| 5 | in property<string> hello: "hello" ; |
| 6 | in property<string> number: "42.56" ; |
| 7 | in property<string> invalid: "132a" ; |
| 8 | in property<string> negative: "-1200000.1" ; |
| 9 | in property<string> empty; |
| 10 | |
| 11 | in-out property<float> number_as_float: number.to_float(); |
| 12 | in-out property<float> negative_as_float: negative.to_float(); |
| 13 | in-out property<bool> test_is_float: !hello.is_float() && number.is_float() && |
| 14 | !invalid.is_float() && negative.is_float(); |
| 15 | |
| 16 | out property<bool> test: test_is_float && 42.56001 - number_as_float < 0.001 && "123" .to-float() == 123 |
| 17 | && "" .to-float() == 0 && hello.to-float() == 0 && 0 == invalid.to-float() && empty.to-float() == 0; |
| 18 | } |
| 19 | |
| 20 | |
| 21 | /* |
| 22 | |
| 23 | ```cpp |
| 24 | auto fuzzy_compare = [](float a, float b) { return std::abs(a - b) < 0.00000001; }; |
| 25 | auto handle = TestCase::create(); |
| 26 | const TestCase &instance = *handle; |
| 27 | assert(instance.get_test_is_float()); |
| 28 | assert(fuzzy_compare(instance.get_number_as_float(), 42.56)); |
| 29 | assert(fuzzy_compare(instance.get_negative_as_float(), -1200000.1)); |
| 30 | assert(instance.get_test()); |
| 31 | ``` |
| 32 | |
| 33 | ```rust |
| 34 | let instance = TestCase::new().unwrap(); |
| 35 | assert!(instance.get_test_is_float()); |
| 36 | assert_eq!(instance.get_number_as_float(), 42.56); |
| 37 | assert_eq!(instance.get_negative_as_float(), -1200000.1); |
| 38 | assert!(instance.get_test()); |
| 39 | ``` |
| 40 | |
| 41 | ```js |
| 42 | function n(a) { return Math.round(a*10000) } |
| 43 | var instance = new slint.TestCase({}); |
| 44 | assert(instance.test_is_float); |
| 45 | assert.equal(n(instance.number_as_float), n(42.56)); |
| 46 | assert.equal(n(instance.negative_as_float/1000), n(-1200000.1/1000)); |
| 47 | assert(instance.test); |
| 48 | ``` |
| 49 | |
| 50 | */ |
| 51 | |