Add a failing test to add rationals
This commit is contained in:
parent
9c52bcb040
commit
1b816e19df
1 changed files with 11 additions and 2 deletions
|
@ -1,4 +1,6 @@
|
||||||
|
/* types/src/number/add.rs
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use super::{Int, Flt, Real};
|
use super::{Int, Flt, Real};
|
||||||
|
@ -9,6 +11,7 @@ impl Add for Real {
|
||||||
fn add(self, other: Real) -> Real {
|
fn add(self, other: Real) -> Real {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(Real::Integer(v), Real::Integer(ov)) => Real::Integer(v + ov),
|
(Real::Integer(v), Real::Integer(ov)) => Real::Integer(v + ov),
|
||||||
|
// TODO: The rest.
|
||||||
_ => Real::Integer(0)
|
_ => Real::Integer(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +23,14 @@ mod tests {
|
||||||
use number::Real;
|
use number::Real;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn integer_add_works() {
|
fn integer_addition_works() {
|
||||||
let result = Real::Integer(3) + Real::Integer(5);
|
let result = Real::Integer(3) + Real::Integer(5);
|
||||||
assert_eq!(result, Real::Integer(8));
|
assert_eq!(result, Real::Integer(8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rational_addition_works() {
|
||||||
|
let result = Real::Rational(1, 4) + Real::Rational(1, 4);
|
||||||
|
assert_eq!(result, Real::Rational(1, 2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue