Skip to content

Commit

Permalink
moved operation tests to each operations corresponding file
Browse files Browse the repository at this point in the history
  • Loading branch information
ludverse committed Mar 13, 2024
1 parent 9a482d6 commit 620e1fc
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 78 deletions.
24 changes: 24 additions & 0 deletions src/operations/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn add_numbers() {
let res_type = Operation::Add.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Number));
}

#[test]
fn add_strings() {
let res_type = Operation::Add.typ(&Type::String, &Type::String);
assert_eq!(res_type, Ok(Type::String));
}

#[test]
fn cannot_add_different() {
assert!(Operation::Add.typ(&Type::String, &Type::Number).is_err())
}
}
18 changes: 18 additions & 0 deletions src/operations/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn div_numbers() {
let res_type = Operation::Div.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Number));
}

#[test]
fn cannot_div_different() {
assert!(Operation::Div.typ(&Type::String, &Type::Number).is_err())
}
}
24 changes: 24 additions & 0 deletions src/operations/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn eq_numbers() {
let res_type = Operation::Eq.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Bool));
}

#[test]
fn eq_strings() {
let res_type = Operation::Eq.typ(&Type::String, &Type::String);
assert_eq!(res_type, Ok(Type::Bool));
}

#[test]
fn cannot_eq_different() {
assert!(Operation::Eq.typ(&Type::String, &Type::Number).is_err())
}
}
18 changes: 18 additions & 0 deletions src/operations/gt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn gt_numbers() {
let res_type = Operation::Gt.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Bool));
}

#[test]
fn cannot_gt_different() {
assert!(Operation::Gt.typ(&Type::String, &Type::Number).is_err())
}
}
18 changes: 18 additions & 0 deletions src/operations/gte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn gte_numbers() {
let res_type = Operation::Gte.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Bool));
}

#[test]
fn cannot_gte_different() {
assert!(Operation::Gte.typ(&Type::String, &Type::Number).is_err())
}
}
18 changes: 18 additions & 0 deletions src/operations/lt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn lt_numbers() {
let res_type = Operation::Lt.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Bool));
}

#[test]
fn cannot_lt_different() {
assert!(Operation::Lt.typ(&Type::String, &Type::Number).is_err())
}
}
18 changes: 18 additions & 0 deletions src/operations/lte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn lte_numbers() {
let res_type = Operation::Lte.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Bool));
}

#[test]
fn cannot_lte_different() {
assert!(Operation::Lte.typ(&Type::String, &Type::Number).is_err())
}
}
3 changes: 0 additions & 3 deletions src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,3 @@ impl Operation {
res.expect("invalid operation slipped through to the interpreter after a valid operation check")
}
}

#[cfg(test)]
mod tests;
18 changes: 18 additions & 0 deletions src/operations/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn mul_numbers() {
let res_type = Operation::Mul.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Number));
}

#[test]
fn cannot_mul_different() {
assert!(Operation::Mul.typ(&Type::String, &Type::Number).is_err())
}
}
18 changes: 18 additions & 0 deletions src/operations/rem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn rem_numbers() {
let res_type = Operation::Rem.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Number));
}

#[test]
fn cannot_rem_different() {
assert!(Operation::Rem.typ(&Type::String, &Type::Number).is_err())
}
}
18 changes: 18 additions & 0 deletions src/operations/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
_ => None
}
}

#[cfg(test)]
mod tests {
use crate::types::Type;

use super::super::Operation;

#[test]
fn sub_numbers() {
let res_type = Operation::Sub.typ(&Type::Number, &Type::Number);
assert_eq!(res_type, Ok(Type::Number));
}

#[test]
fn cannot_sub_different() {
assert!(Operation::Sub.typ(&Type::String, &Type::Number).is_err())
}
}
75 changes: 0 additions & 75 deletions src/operations/tests.rs

This file was deleted.

0 comments on commit 620e1fc

Please sign in to comment.