Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Feb 10, 2024
1 parent 740f46f commit f60b2c1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/dual/dual1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,34 @@ impl Dual {
}
}

fn __lt__(&self, other:DualOrF64) -> PyResult<bool> {
match other {
DualOrF64::Dual(d) => Ok(self < &d),
DualOrF64::F64(f) => Ok(self < &f)
}
}

fn __le__(&self, other:DualOrF64) -> PyResult<bool> {
match other {
DualOrF64::Dual(d) => Ok(self <= &d),
DualOrF64::F64(f) => Ok(self <= &f)
}
}

fn __gt__(&self, other:DualOrF64) -> PyResult<bool> {
match other {
DualOrF64::Dual(d) => Ok(self > &d),
DualOrF64::F64(f) => Ok(self > &f)
}
}

fn __ge__(&self, other:DualOrF64) -> PyResult<bool> {
match other {
DualOrF64::Dual(d) => Ok(self >= &d),
DualOrF64::F64(f) => Ok(self >= &f)
}
}

fn __neg__(&self) -> Self {-self}

fn __add__(&self, other: DualOrF64) -> Self {
Expand Down
19 changes: 17 additions & 2 deletions tests/test_dualrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,20 @@ def test_eq_ne(x_1):

def test_lt():
assert Dual(1, ["x"], []) < Dual(2, ["y"], [])
assert Dual(1, "x") < 10
assert not Dual(1, "x") < 0
assert Dual(1, ["x"], []) < 10
assert 0.5 < Dual(1, ["x"], [])

def test_le():
assert Dual(1.0, ["x"], []) <= Dual(1.0, ["y"], [])
assert Dual(1, ["x"], []) <= 1.0
assert 1.0 <= Dual(1.0, ["x"], [])

def test_gt():
assert Dual(3, ["x"], []) > Dual(2, ["y"], [])
assert Dual(1, ["x"], []) > 0.5
assert 0.5 > Dual(0.3, ["x"], [])

def test_ge():
assert Dual(1.0, ["x"], []) >= Dual(1.0, ["y"], [])
assert Dual(1, ["x"], []) >= 1.0
assert 1.0 >= Dual(1.0, ["x"], [])

0 comments on commit f60b2c1

Please sign in to comment.