slint/tests/cases/expr/cos.slint
2024-08-15 14:52:13 +02:00

40 lines
1.3 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
component TestCase inherits Window {
out property<float> t1: cos(0);
out property<float> t2: cos(180deg);
out property<float> t3: cos(60deg);
out property<float> t4: cos(90deg);
out property<bool> test: (0deg.cos() - 1.0).abs() < 0.00001 && 90deg.cos().abs() < 0.000001;
}
/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(std::abs(instance.get_t1() - 1.0) < 0.0001);
assert(std::abs(instance.get_t2() + 1.0) < 0.0001);
assert(std::abs(instance.get_t3() - 0.5) < 0.0001);
assert(std::abs(instance.get_t4()) < 0.0001);
assert(instance.get_test());
```
```rust
let instance = TestCase::new().unwrap();
assert!((instance.get_t1() - 1.0).abs() < 0.0001);
assert!((instance.get_t2() + 1.0).abs() < 0.0001);
assert!((instance.get_t3() - 0.5).abs() < 0.0001);
assert!((instance.get_t4()).abs() < 0.0001);
assert!(instance.get_test());
```
```js
var instance = new slint.TestCase({});
assert(Math.abs(instance.t1 - 1) < Number.EPSILON);
assert(Math.abs(instance.t2 - -1) < Number.EPSILON);
assert(Math.abs(instance.t3 - 0.5) < Number.EPSILON);
assert(Math.abs(instance.t4) < Number.EPSILON);
assert(instance.test);
```
*/