Skip to content

Commit

Permalink
Fixes related to infix ops PR (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo authored May 27, 2024
1 parent d3ab92f commit 115ccb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum Operation {
Subtract,
Multiply,
Divide,
IntegerDivide,
Exponentiate,
Modulus,

Expand Down Expand Up @@ -91,6 +92,7 @@ impl Gate {
Operation::Subtract => left_input - right_input,
Operation::Multiply => left_input * right_input,
Operation::Divide => left_input / right_input, // Will panic if right_input is zero
Operation::IntegerDivide => left_input / right_input, // Will panic if right_input is zero
Operation::Exponentiate => left_input.pow(right_input),
Operation::Modulus => left_input % right_input, // Will panic if right_input is zero
Operation::Equals => (left_input == right_input) as u32,
Expand Down Expand Up @@ -205,8 +207,8 @@ impl Circuit {
for &input in &[gate.left_input, gate.right_input] {
dependency_graph
.entry(input)
.or_insert_with(HashSet::new)
.insert(output);
.or_insert_with(Vec::new)
.push(output);
*in_degree.entry(output).or_insert(0) += 1;
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/x_mul_x.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use sim_circuit::circuit::{Circuit, Gate, Node, Operation};

#[test]
fn test_x_mul_x() {
let mut circuit = Circuit::new();

// Initialize nodes
circuit.add_node(1, Node::new()).unwrap();
circuit.add_node(2, Node::new()).unwrap();

// out = x * x
circuit
.add_gate(Gate::new(Operation::Multiply, 1, 1, 2))
.unwrap();

let inputs = vec![5];
let outputs = circuit.execute(&inputs).unwrap();

assert_eq!(outputs, vec![25]);
}

0 comments on commit 115ccb5

Please sign in to comment.