Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Feature/improve unit tests coverage #189

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1824b93
Added more unit tests for poly
rutefig Dec 25, 2023
2e726a2
Added more unit tests for ast/query
rutefig Dec 25, 2023
c831c88
Formatting fixes
rutefig Dec 25, 2023
7483dd3
Added more unit tests for dsl/mod
rutefig Dec 27, 2023
5c96d01
Added unit tests for Constraint on dsl::cb
rutefig Dec 29, 2023
66661e2
Added more unit tests for compiler/step_selector
rutefig Jan 8, 2024
e9340b9
Added more unit tests for compiler
rutefig Jan 11, 2024
4dd470b
fixed some mistakes
rutefig Jan 11, 2024
cd68d49
Added unit tests for Super Circuit
rutefig Jan 13, 2024
82ade6b
fix formatting and clippy
rutefig Jan 14, 2024
0cbe7d5
fixes from PR review
rutefig Jan 20, 2024
6198b55
Merge branch 'main' into feature/improve-unit-tests-coverage
rutefig Jan 23, 2024
de43768
fixed tests failing after merge conflicts
rutefig Jan 23, 2024
3844c33
ignore test for compile_phase2 before flagging compilation phases not…
rutefig Jan 29, 2024
f170e35
ignore test when exposing a non existing signal - waiting for check t…
rutefig Jan 29, 2024
df720ac
Merge branch 'main' into feature/improve-unit-tests-coverage
rutefig Feb 29, 2024
86fe3e5
improved some tests on plonkish::ir::sc
rutefig Mar 4, 2024
b274c59
fixed mistakes for poly
rutefig Mar 4, 2024
f8db6ac
formatting
rutefig Mar 4, 2024
c131714
removed wrong tests for query
rutefig Mar 4, 2024
bfe9fd2
Merge branch 'main' into feature/improve-unit-tests-coverage
rutefig Mar 4, 2024
f860065
formatting
rutefig Mar 4, 2024
25e4578
Merge branch 'feature/improve-unit-tests-coverage' of github.com:rute…
rutefig Mar 4, 2024
4a64cac
ignore pointer and use default debug for sc
rutefig Mar 18, 2024
8ad9cc0
improved tests on frontend::dsl::sc
rutefig Mar 20, 2024
c4234b3
test sub circuit with ast for super circuit frontend
rutefig Mar 20, 2024
9d9fcb8
refactor for poly and fixed some scopes on sc
rutefig Mar 21, 2024
31cf4a8
formatting
rutefig Mar 21, 2024
8be82d7
Merge branch 'main' into feature/improve-unit-tests-coverage
rutefig Mar 21, 2024
4fb0b66
clippy fix
rutefig Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 239 additions & 0 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,243 @@ mod tests {
let expr5: Expr<Fr, Queriable<Fr>> = Expr::Pow(Box::new(Expr::Const(a)), 2);
assert_eq!(format!("{:?}", expr5), "(0xa)^2");
}

#[test]
fn test_add_fmt() {
let a: Fr = 10.into();
let b: Fr = 20.into();

let expr2: Expr<Fr, Queriable<Fr>> = Expr::Const(a) + Expr::Const(b);
let expr2_vec: Expr<Fr, Queriable<Fr>> = Expr::Sum(vec![Expr::Const(a), Expr::Const(b)]);
assert_eq!(
format!("{:?}", expr2),
format!("{:?}", expr2_vec),
"(0xa + 0x14)"
);

let expr3: Expr<Fr, Queriable<Fr>> = Expr::Const(a) + Expr::Const(b) + Expr::Const(a);
let expr3_vec: Expr<Fr, Queriable<Fr>> =
Expr::Sum(vec![Expr::Const(a), Expr::Const(b), Expr::Const(a)]);
assert_eq!(
format!("{:?}", expr3),
format!("{:?}", expr3_vec),
"(0xa + 0x14 + 0xa)"
);
}

#[test]
fn test_sub_fmt() {
let a: Fr = 10.into();
let b: Fr = 20.into();

let expr2: Expr<Fr, Queriable<Fr>> = Expr::Const(a) - Expr::Const(b);
let expr2_vec: Expr<Fr, Queriable<Fr>> =
Expr::Sum(vec![Expr::Const(a), Expr::Const(b).neg()]);
assert_eq!(
format!("{:?}", expr2),
format!("{:?}", expr2_vec),
"(0xa + (-0x14))"
);

let expr3: Expr<Fr, Queriable<Fr>> = Expr::Const(a) - Expr::Const(b) - Expr::Const(a);
let expr3_vec: Expr<Fr, Queriable<Fr>> = Expr::Sum(vec![
Expr::Const(a),
Expr::Const(b).neg(),
Expr::Const(a).neg(),
]);
assert_eq!(
format!("{:?}", expr3),
format!("{:?}", expr3_vec),
"(0xa + (-0x14) + (-0xa))"
);
}

#[test]
fn test_mul_fmt() {
let a: Fr = 10.into();
let b: Fr = 20.into();

let expr2: Expr<Fr, Queriable<Fr>> = Expr::Const(a) * Expr::Const(b);
let expr2_vec: Expr<Fr, Queriable<Fr>> = Expr::Mul(vec![Expr::Const(a), Expr::Const(b)]);
assert_eq!(
format!("{:?}", expr2),
format!("{:?}", expr2_vec),
"(0xa * 0x14)"
);

let expr3: Expr<Fr, Queriable<Fr>> = Expr::Const(a) * Expr::Const(b) * Expr::Const(a);
let expr3_vec: Expr<Fr, Queriable<Fr>> =
Expr::Mul(vec![Expr::Const(a), Expr::Const(b), Expr::Const(a)]);
assert_eq!(
format!("{:?}", expr3),
format!("{:?}", expr3_vec),
"(0xa * 0x14 * 0xa)"
);
}

#[test]
fn test_neg_fmt() {
let a: Fr = 10.into();

let expr1: Expr<Fr, Queriable<Fr>> = Expr::Const(a).neg();
let expr1_box: Expr<Fr, Queriable<Fr>> = Expr::Neg(Box::new(Expr::Const(a)));
assert_eq!(format!("{:?}", expr1), format!("{:?}", expr1_box), "(-0xa)");
}

#[test]
fn test_next_for_forward_signal() {
let forward_signal = ForwardSignal {
id: 0,
phase: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Forward(forward_signal, false);
let next_queriable = queriable.next();

assert_eq!(next_queriable, Queriable::Forward(forward_signal, true));
}

#[test]
#[should_panic(expected = "jarrl: cannot rotate next(forward)")]
fn test_next_for_forward_signal_panic() {
let forward_signal = ForwardSignal {
id: 0,
phase: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Forward(forward_signal, true);
let _ = queriable.next(); // This should panic
}

#[test]
fn test_next_for_shared_signal() {
let shared_signal = SharedSignal {
id: 0,
phase: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Shared(shared_signal, 0);
let next_queriable = queriable.next();

assert_eq!(next_queriable, Queriable::Shared(shared_signal, 1));
}

#[test]
fn test_next_for_fixed_signal() {
let fixed_signal = FixedSignal {
id: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Fixed(fixed_signal, 0);
let next_queriable = queriable.next();

assert_eq!(next_queriable, Queriable::Fixed(fixed_signal, 1));
}

#[test]
#[should_panic(expected = "can only next a forward, shared, fixed, or halo2 column")]
fn test_next_for_internal_signal_panic() {
let internal_signal = InternalSignal {
id: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Internal(internal_signal);
let _ = queriable.next(); // This should panic
}

#[test]
fn test_prev_for_shared_signal() {
let shared_signal = SharedSignal {
id: 0,
phase: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Shared(shared_signal, 1);
let prev_queriable = queriable.prev();

assert_eq!(prev_queriable, Queriable::Shared(shared_signal, 0));
}

#[test]
fn test_prev_for_fixed_signal() {
let fixed_signal = FixedSignal {
id: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Fixed(fixed_signal, 1);
let prev_queriable = queriable.prev();

assert_eq!(prev_queriable, Queriable::Fixed(fixed_signal, 0));
}

#[test]
#[should_panic(expected = "can only prev a shared or fixed column")]
fn test_prev_for_forward_signal_panic() {
let forward_signal = ForwardSignal {
id: 0,
phase: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Forward(forward_signal, true);
let _ = queriable.prev(); // This should panic
}

#[test]
#[should_panic(expected = "can only prev a shared or fixed column")]
fn test_prev_for_internal_signal_panic() {
let internal_signal = InternalSignal {
id: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Internal(internal_signal);
let _ = queriable.prev(); // This should panic
}

#[test]
fn test_rot_for_shared_signal() {
let shared_signal = SharedSignal {
id: 0,
phase: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Shared(shared_signal, 1);
let rot_queriable = queriable.rot(2);

assert_eq!(rot_queriable, Queriable::Shared(shared_signal, 3));
}

#[test]
fn test_rot_for_fixed_signal() {
let fixed_signal = FixedSignal {
id: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Fixed(fixed_signal, 1);
let rot_queriable = queriable.rot(2);

assert_eq!(rot_queriable, Queriable::Fixed(fixed_signal, 3));
}

#[test]
#[should_panic(expected = "can only rot a shared or fixed column")]
fn test_rot_for_forward_signal_panic() {
let forward_signal = ForwardSignal {
id: 0,
phase: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Forward(forward_signal, true);
let _ = queriable.rot(2); // This should panic
}

#[test]
#[should_panic(expected = "can only rot a shared or fixed column")]
fn test_rot_for_internal_signal_panic() {
let internal_signal = InternalSignal {
id: 0,
annotation: "",
};
let queriable: Queriable<Fr> = Queriable::Internal(internal_signal);
let _ = queriable.rot(2); // This should panic
}
}
47 changes: 47 additions & 0 deletions src/frontend/dsl/cb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,51 @@ mod tests {
matches!(v[1], Expr::Const(c) if c == 40u64.field())) &&
matches!(v[1], Expr::Const(c) if c == 10u64.field())));
}

#[test]
fn test_constraint_from_queriable() {
// Create a Queriable instance and convert it to a Constraint
let queriable = Queriable::StepTypeNext(StepTypeHandler::new("test_step".to_owned()));
let constraint: Constraint<Fr> = Constraint::from(queriable);

assert_eq!(constraint.annotation, "test_step");
assert!(
matches!(constraint.expr, Expr::Query(Queriable::StepTypeNext(s)) if
matches!(s, StepTypeHandler {id: _id, annotation: "test_step"}))
);
assert!(matches!(constraint.typing, Typing::Boolean));
}

#[test]
fn test_constraint_from_expr() {
// Create an expression and convert it to a Constraint
let expr = <u64 as ToExpr<Fr, Queriable<Fr>>>::expr(&10) * 20u64.expr();
let constraint: Constraint<Fr> = Constraint::from(expr);

// returns "10 * 20"
assert!(matches!(constraint.expr, Expr::Mul(v) if v.len() == 2 &&
matches!(v[0], Expr::Const(c) if c == 10u64.field()) &&
matches!(v[1], Expr::Const(c) if c == 20u64.field())));
assert!(matches!(constraint.typing, Typing::Unknown));
}

#[test]
fn test_constraint_from_int() {
// Create an integer and convert it to a Constraint
let constraint: Constraint<Fr> = Constraint::from(10);

// returns "10"
assert!(matches!(constraint.expr, Expr::Const(c) if c == 10u64.field()));
assert!(matches!(constraint.typing, Typing::Unknown));
}

#[test]
fn test_constraint_from_bool() {
// Create a boolean and convert it to a Constraint
let constraint: Constraint<Fr> = Constraint::from(true);

assert_eq!(constraint.annotation, "0x1");
assert!(matches!(constraint.expr, Expr::Const(c) if c == 1u64.field()));
assert!(matches!(constraint.typing, Typing::Unknown));
}
}
Loading
Loading