#![cfg(test)]
extern crate acme_graphs as graphs;
use graphs::scg::Scg;
#[test]
#[ignore = "Test fails; needs to be fixed"]
fn test_scg() {
let mut dag = Scg::new();
let x = dag.variable(1f64);
let y = dag.variable(2f64);
let c = dag.add(x, y).unwrap();
assert_eq!(*dag.get_value(c).unwrap(), 3.0);
let d = dag.mul(c, y).unwrap();
assert_eq!(*dag.get_value(d).unwrap(), 6.0);
let gc = dag.gradient_at(c).unwrap();
assert_eq!(gc[&x], 1.0);
assert_eq!(gc[&y], 1.0);
let gd = dag.backward().unwrap();
assert_eq!(gd[&x], 2.0);
assert_eq!(gd[&y], 5.0);
}
#[test]
#[ignore = "This test is failing"]
fn test_backward() {
let mut dag = Scg::new();
let x = dag.variable(1f64);
let y = dag.variable(2f64);
let c = dag.add(x, y).unwrap();
let d = dag.mul(c, y).unwrap();
assert_eq!(*dag.get_value(c).unwrap(), -1.0);
assert_eq!(*dag.get_value(d).unwrap(), -2.0);
let gc = dag.gradient_at(c).unwrap();
assert_eq!(gc[&x], 1.0);
assert_eq!(gc[&y], -1.0);
let gd = dag.backward().unwrap();
assert_eq!(gd[&x], 2.0);
assert_eq!(gd[&y], -3.0);
}