Skip to content

Commit

Permalink
Add and AddAssign tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Martina committed Jan 13, 2023
1 parent 95f8750 commit d3550c1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ mod test {
prop_assert!(&x.to_biguint() < p);
}

#[test]
// Property-based test that ensures, for 100 {x} and {y} values that are randomly generated each time tests are run, that an addition between two felts {x} and {y} and doesn't fall outside the range [0, p]. The values of {x} and {y} can be either [0] or a very large number.
fn add_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") {
let x = &Felt::parse_bytes(x.as_bytes(), 10).unwrap();
let y = &Felt::parse_bytes(y.as_bytes(), 10).unwrap();
let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap();

let result = x + y;
let as_uint = &result.to_biguint();
println!("x: {}, y: {}, result: {}", x, y, result);
prop_assert!(as_uint < p, "{}", as_uint);
}
#[test]
// Property-based test that ensures, for 100 {x} and {y} values that are randomly generated each time tests are run, that an addition with assignment between two felts {x} and {y} and doesn't fall outside the range [0, p]. The values of {x} and {y} can be either [0] or a very large number.
fn add_assign_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") {
let mut x = Felt::parse_bytes(x.as_bytes(), 10).unwrap();
let y = &Felt::parse_bytes(y.as_bytes(), 10).unwrap();
let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap();

x += y;
let as_uint = &x.to_biguint();
prop_assert!(as_uint < p, "{}", as_uint);
}

#[test]
// Property-based test that ensures, for 100 {x} and {y} values that are randomly generated each time tests are run, that a multiplication between two felts {x} and {y} and doesn't fall outside the range [0, p]. The values of {x} and {y} can be either [0] or a very large number.
fn mul_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") {
Expand Down

1 comment on commit d3550c1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: d3550c1 Previous: ef1923d Ratio
cairo_run(cairo_programs/benchmarks/compare_arrays_200000.json 976037572 ns/iter (± 26300856) 692885744 ns/iter (± 2617402) 1.41
cairo_run(cairo_programs/benchmarks/factorial_multirun.json 375940101 ns/iter (± 10293691) 271896019 ns/iter (± 848772) 1.38
cairo_run(cairo_programs/benchmarks/fibonacci_1000_multirun.json 172756486 ns/iter (± 4565595) 126525398 ns/iter (± 437284) 1.37
cairo_run(cairo_programs/benchmarks/integration_builtins.json 567066427 ns/iter (± 16814133) 396332014 ns/iter (± 1950900) 1.43
cairo_run(cairo_programs/benchmarks/linear_search.json 122409752 ns/iter (± 4371668) 87546540 ns/iter (± 393531) 1.40
cairo_run(cairo_programs/benchmarks/keccak_integration_benchmark.json 1774110500 ns/iter (± 30943829) 1243985826 ns/iter (± 9622338) 1.43
cairo_run(cairo_programs/benchmarks/secp_integration_benchmark.json 2106465752 ns/iter (± 46492835) 1409686395 ns/iter (± 5538410) 1.49
cairo_run(cairo_programs/benchmarks/blake2s_integration_benchmark.json 1652305441 ns/iter (± 29805511) 1115624223 ns/iter (± 7224468) 1.48
cairo_run(cairo_programs/benchmarks/dict_integration_benchmark.json 1147396202 ns/iter (± 20341854) 797304241 ns/iter (± 2615964) 1.44
cairo_run(cairo_programs/benchmarks/math_integration_benchmark.json 554302538 ns/iter (± 13661041) 405382200 ns/iter (± 1303969) 1.37
cairo_run(cairo_programs/benchmarks/memory_integration_benchmark.json 647699485 ns/iter (± 57930334) 447107987 ns/iter (± 5673860) 1.45
cairo_run(cairo_programs/benchmarks/math_cmp_and_pow_integration_benchmark.json 25870860 ns/iter (± 775543) 18252453 ns/iter (± 83205) 1.42
cairo_run(cairo_programs/benchmarks/operations_with_data_structures_benchmarks.json 2509588988 ns/iter (± 65414987) 1694858011 ns/iter (± 25946957) 1.48
cairo_run(cairo_programs/benchmarks/uint256_integration_benchmark.json 1724548191 ns/iter (± 44666722) 1141206098 ns/iter (± 6641417) 1.51

This comment was automatically generated by workflow using github-action-benchmark.

CC: @unbalancedparentheses

Please sign in to comment.