1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
3
4export 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
24auto fuzzy_compare = [](float a, float b) { return std::abs(a - b) < 0.00000001; };
25auto handle = TestCase::create();
26const TestCase &instance = *handle;
27assert(instance.get_test_is_float());
28assert(fuzzy_compare(instance.get_number_as_float(), 42.56));
29assert(fuzzy_compare(instance.get_negative_as_float(), -1200000.1));
30assert(instance.get_test());
31```
32
33```rust
34let instance = TestCase::new().unwrap();
35assert!(instance.get_test_is_float());
36assert_eq!(instance.get_number_as_float(), 42.56);
37assert_eq!(instance.get_negative_as_float(), -1200000.1);
38assert!(instance.get_test());
39```
40
41```js
42function n(a) { return Math.round(a*10000) }
43var instance = new slint.TestCase({});
44assert(instance.test_is_float);
45assert.equal(n(instance.number_as_float), n(42.56));
46assert.equal(n(instance.negative_as_float/1000), n(-1200000.1/1000));
47assert(instance.test);
48```
49
50*/
51