Skip to content

Commit

Permalink
tests moved into module
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jan 3, 2024
1 parent 6e4f00b commit 98c3eae
Showing 1 changed file with 120 additions and 106 deletions.
226 changes: 120 additions & 106 deletions src/queries.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -81,120 +81,134 @@ fn usort(input: Array<u64>) -> Array<felt252> {
result
}

#[cfg(test)]
mod tests {
use cairo_verifier::{
channel::channel::ChannelTrait, queries::{usort, sample_random_queries, generate_queries},
};

#[test]
#[available_gas(9999999999)]
fn test_usort_0() {
let unsorted: Array<u64> = array![3];
assert(usort(unsorted) == array![3], 'Invalid sorting');
}
#[test]
#[available_gas(9999999999)]
fn test_usort_0() {
let unsorted: Array<u64> = array![3];
assert(usort(unsorted) == array![3], 'Invalid sorting');
}

#[test]
#[available_gas(9999999999)]
fn test_usort_1() {
let unsorted: Array<u64> = array![];
assert(usort(unsorted) == array![], 'Invalid sorting');
}
#[test]
#[available_gas(9999999999)]
fn test_usort_1() {
let unsorted: Array<u64> = array![];
assert(usort(unsorted) == array![], 'Invalid sorting');
}

#[test]
#[available_gas(9999999999)]
fn test_usort_2() {
let unsorted: Array<u64> = array![742, 360, 952, 891, 634, 707, 582, 264, 806, 720];
assert(
usort(unsorted) == array![264, 360, 582, 634, 707, 720, 742, 806, 891, 952],
'Invalid sorting'
);
}
#[test]
#[available_gas(9999999999)]
fn test_usort_2() {
let unsorted: Array<u64> = array![742, 360, 952, 891, 634, 707, 582, 264, 806, 720];
assert(
usort(unsorted) == array![264, 360, 582, 634, 707, 720, 742, 806, 891, 952],
'Invalid sorting'
);
}

#[test]
#[available_gas(9999999999)]
fn test_usort_3() {
let unsorted: Array<u64> = array![6, 3, 4, 3, 9, 8, 0, 10, 5, 6];
assert(usort(unsorted) == array![0, 3, 4, 5, 6, 8, 9, 10], 'Invalid sorting');
}
#[test]
#[available_gas(9999999999)]
fn test_usort_3() {
let unsorted: Array<u64> = array![6, 3, 4, 3, 9, 8, 0, 10, 5, 6];
assert(usort(unsorted) == array![0, 3, 4, 5, 6, 8, 9, 10], 'Invalid sorting');
}

#[test]
#[available_gas(9999999999)]
fn test_usort_4() {
let unsorted: Array<u64> = array![3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
assert(usort(unsorted) == array![3], 'Invalid sorting');
}
#[test]
#[available_gas(9999999999)]
fn test_usort_4() {
let unsorted: Array<u64> = array![3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
assert(usort(unsorted) == array![3], 'Invalid sorting');
}

#[test]
#[available_gas(9999999999)]
fn test_usort_5() {
let unsorted: Array<u64> = array![7, 3];
assert(usort(unsorted) == array![3, 7], 'Invalid sorting');
}
#[test]
#[available_gas(9999999999)]
fn test_usort_5() {
let unsorted: Array<u64> = array![7, 3];
assert(usort(unsorted) == array![3, 7], 'Invalid sorting');
}

#[test]
#[available_gas(9999999999)]
fn test_sample_random_queries_1() {
let mut channel = ChannelTrait::new(
u256 { low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7 }
);
let queries = sample_random_queries(ref channel, 1, 12389012333);
assert(queries.len() == 4, 'Invalid value');
assert(*queries.at(0) == 0xc53fdd1e, 'Invalid value');
assert(*queries.at(1) == 0x166d56d3d, 'Invalid value');
assert(*queries.at(2) == 0x1e563d10b, 'Invalid value');
assert(*queries.at(3) == 0x2d9a2434f, 'Invalid value');
}
#[test]
#[available_gas(9999999999)]
fn test_sample_random_queries_1() {
let mut channel = ChannelTrait::new(
u256 {
low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7
}
);
let queries = sample_random_queries(ref channel, 1, 12389012333);
assert(queries.len() == 4, 'Invalid value');
assert(*queries.at(0) == 0xc53fdd1e, 'Invalid value');
assert(*queries.at(1) == 0x166d56d3d, 'Invalid value');
assert(*queries.at(2) == 0x1e563d10b, 'Invalid value');
assert(*queries.at(3) == 0x2d9a2434f, 'Invalid value');
}

#[test]
#[available_gas(9999999999)]
fn test_sample_random_queries_2() {
let mut channel = ChannelTrait::new(
u256 { low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7 }
);
let queries = sample_random_queries(ref channel, 10, 99809818624);
assert(queries.len() == 12, 'Invalid value');
assert(*queries.at(0) == 0x1405a07e8c, 'Invalid value');
assert(*queries.at(1) == 0x982d6fc79, 'Invalid value');
assert(*queries.at(2) == 0x6188b67d1, 'Invalid value');
assert(*queries.at(3) == 0xa733f8ed8, 'Invalid value');
assert(*queries.at(4) == 0x557cce2e5, 'Invalid value');
assert(*queries.at(5) == 0xbf23e4bf7, 'Invalid value');
assert(*queries.at(6) == 0x3247d4098, 'Invalid value');
assert(*queries.at(7) == 0xca83fb21d, 'Invalid value');
assert(*queries.at(8) == 0xc2321969b, 'Invalid value');
assert(*queries.at(9) == 0x52d896136, 'Invalid value');
assert(*queries.at(10) == 0xe4da8dce0, 'Invalid value');
assert(*queries.at(11) == 0x8cf7e0675, 'Invalid value');
}
#[test]
#[available_gas(9999999999)]
fn test_sample_random_queries_2() {
let mut channel = ChannelTrait::new(
u256 {
low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7
}
);
let queries = sample_random_queries(ref channel, 10, 99809818624);
assert(queries.len() == 12, 'Invalid value');
assert(*queries.at(0) == 0x1405a07e8c, 'Invalid value');
assert(*queries.at(1) == 0x982d6fc79, 'Invalid value');
assert(*queries.at(2) == 0x6188b67d1, 'Invalid value');
assert(*queries.at(3) == 0xa733f8ed8, 'Invalid value');
assert(*queries.at(4) == 0x557cce2e5, 'Invalid value');
assert(*queries.at(5) == 0xbf23e4bf7, 'Invalid value');
assert(*queries.at(6) == 0x3247d4098, 'Invalid value');
assert(*queries.at(7) == 0xca83fb21d, 'Invalid value');
assert(*queries.at(8) == 0xc2321969b, 'Invalid value');
assert(*queries.at(9) == 0x52d896136, 'Invalid value');
assert(*queries.at(10) == 0xe4da8dce0, 'Invalid value');
assert(*queries.at(11) == 0x8cf7e0675, 'Invalid value');
}

#[test]
#[available_gas(9999999999)]
fn test_generate_queries_1() {
let mut channel = ChannelTrait::new(
u256 { low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7 }
);
let queries = generate_queries(ref channel, 1, 12389012333);
assert(queries.len() == 4, 'Invalid value');
assert(*queries.at(0) == 0xc53fdd1e, 'Invalid value');
assert(*queries.at(1) == 0x166d56d3d, 'Invalid value');
assert(*queries.at(2) == 0x1e563d10b, 'Invalid value');
assert(*queries.at(3) == 0x2d9a2434f, 'Invalid value');
}
#[test]
#[available_gas(9999999999)]
fn test_generate_queries_1() {
let mut channel = ChannelTrait::new(
u256 {
low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7
}
);
let queries = generate_queries(ref channel, 1, 12389012333);
assert(queries.len() == 4, 'Invalid value');
assert(*queries.at(0) == 0xc53fdd1e, 'Invalid value');
assert(*queries.at(1) == 0x166d56d3d, 'Invalid value');
assert(*queries.at(2) == 0x1e563d10b, 'Invalid value');
assert(*queries.at(3) == 0x2d9a2434f, 'Invalid value');
}

#[test]
#[available_gas(9999999999)]
fn test_generate_queries_2() {
let mut channel = ChannelTrait::new(
u256 { low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7 }
);
let queries = generate_queries(ref channel, 10, 99809818624);
assert(queries.len() == 12, 'Invalid value');
assert(*queries.at(0) == 0x3247d4098, 'Invalid value');
assert(*queries.at(1) == 0x52d896136, 'Invalid value');
assert(*queries.at(2) == 0x557cce2e5, 'Invalid value');
assert(*queries.at(3) == 0x6188b67d1, 'Invalid value');
assert(*queries.at(4) == 0x8cf7e0675, 'Invalid value');
assert(*queries.at(5) == 0x982d6fc79, 'Invalid value');
assert(*queries.at(6) == 0xa733f8ed8, 'Invalid value');
assert(*queries.at(7) == 0xbf23e4bf7, 'Invalid value');
assert(*queries.at(8) == 0xc2321969b, 'Invalid value');
assert(*queries.at(9) == 0xca83fb21d, 'Invalid value');
assert(*queries.at(10) == 0xe4da8dce0, 'Invalid value');
assert(*queries.at(11) == 0x1405a07e8c, 'Invalid value');
#[test]
#[available_gas(9999999999)]
fn test_generate_queries_2() {
let mut channel = ChannelTrait::new(
u256 {
low: 0xf7685ebd40e852b164633a4acbd3244c, high: 0xe8e77626586f73b955364c7b4bbf0bb7
}
);
let queries = generate_queries(ref channel, 10, 99809818624);
assert(queries.len() == 12, 'Invalid value');
assert(*queries.at(0) == 0x3247d4098, 'Invalid value');
assert(*queries.at(1) == 0x52d896136, 'Invalid value');
assert(*queries.at(2) == 0x557cce2e5, 'Invalid value');
assert(*queries.at(3) == 0x6188b67d1, 'Invalid value');
assert(*queries.at(4) == 0x8cf7e0675, 'Invalid value');
assert(*queries.at(5) == 0x982d6fc79, 'Invalid value');
assert(*queries.at(6) == 0xa733f8ed8, 'Invalid value');
assert(*queries.at(7) == 0xbf23e4bf7, 'Invalid value');
assert(*queries.at(8) == 0xc2321969b, 'Invalid value');
assert(*queries.at(9) == 0xca83fb21d, 'Invalid value');
assert(*queries.at(10) == 0xe4da8dce0, 'Invalid value');
assert(*queries.at(11) == 0x1405a07e8c, 'Invalid value');
}
}

0 comments on commit 98c3eae

Please sign in to comment.