cuoolcumber
Cargo Check, Format, Fix and Test / cargo CI (push) Has been cancelled Details

This commit is contained in:
Christoph J. Scherr 2024-01-12 14:45:00 +01:00
parent 03a972366b
commit d8d6bb9a67
Signed by: cscherrNT
GPG Key ID: 8E2B45BC51A27EA7
5 changed files with 109 additions and 0 deletions

58
Cargo.lock generated
View File

@ -416,6 +416,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"cucumber", "cucumber",
"futures", "futures",
"rand",
"tokio", "tokio",
] ]
@ -561,6 +562,17 @@ dependencies = [
"slab", "slab",
] ]
[[package]]
name = "getrandom"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]] [[package]]
name = "gherkin" name = "gherkin"
version = "0.14.0" version = "0.14.0"
@ -949,6 +961,12 @@ dependencies = [
"plotters-backend", "plotters-backend",
] ]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.76" version = "1.0.76"
@ -967,6 +985,36 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.8.0" version = "1.8.0"
@ -1027,6 +1075,10 @@ name = "revsqrt"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"criterion", "criterion",
"cucumber",
"futures",
"rand",
"tokio",
] ]
[[package]] [[package]]
@ -1347,6 +1399,12 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.89" version = "0.2.89"

View File

@ -9,6 +9,7 @@ edition = "2021"
futures = "0.3.30" futures = "0.3.30"
cucumber = "0.20.2" cucumber = "0.20.2"
tokio = { version = "1.10", features = ["macros", "rt-multi-thread", "time"] } tokio = { version = "1.10", features = ["macros", "rt-multi-thread", "time"] }
rand = "0.8.5"
[[test]] [[test]]
name = "example" # this should be the same as the filename of your test target name = "example" # this should be the same as the filename of your test target

View File

@ -5,6 +5,10 @@ edition = "2021"
[dev-dependencies] [dev-dependencies]
criterion = "0.5.1" criterion = "0.5.1"
futures = "0.3.30"
cucumber = "0.20.2"
tokio = { version = "1.10", features = ["macros", "rt-multi-thread", "time"] }
rand = "0.8.5"
[[bench]] [[bench]]
name = "rsqrt-bench" name = "rsqrt-bench"
@ -17,3 +21,7 @@ path = "src/lib.rs"
[[bin]] [[bin]]
name = "revsqrt" name = "revsqrt"
path = "src/main.rs" path = "src/main.rs"
[[test]]
name = "revsqrt"
harness = false # allows Cucumber to print output instead of libtest

View File

@ -0,0 +1,6 @@
Feature: inverted square root feature
Scenario: If we calculate the inverted square root of a number using fast inverted square root, it's about the same as if we calculate it normally
Given a number
When We calculate the the inverted square root of a number using fast inverted square root
Then The result is about the same as if we calculate it normally

View File

@ -0,0 +1,36 @@
use revsqrt::*;
use cucumber::{given, then, when, World};
use rand;
#[derive(Debug, Default, World)]
pub struct NumWorld {
number: f32,
result: f32,
}
// is n about the same as m?
fn about_same(n: f32, m: f32) -> bool {
(n - m)*1000f32 < 1f32
}
// Steps are defined with `given`, `when` and `then` attributes.
#[given(regex = r"^a number$")]
async fn hungry_cat(world: &mut NumWorld) {
world.number = rand::random();
}
#[when("We calculate the the inverted square root of a number using fast inverted square root")]
async fn calc_fast_inv_sqrt(world: &mut NumWorld) {
world.result = revsqrt::fast_inverse_sqrt(world.number);
}
#[then("The result is about the same as if we calculate it normally")]
async fn comp_result_with_normal(world: &mut NumWorld) {
assert!(about_same(world.number, world.result));
}
#[tokio::main]
async fn main() {
futures::executor::block_on(NumWorld::run("tests/features/book/revsqrt.feature"));
}