Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented as `erlang::is_equal_or_less_than_2`.
- Loading branch information
1 parent
a0c4ca0
commit 1511d7c
Showing
17 changed files
with
2,022 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
lumen_runtime/src/otp/erlang/tests/is_equal_or_less_than_2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use super::*; | ||
|
||
mod with_atom_left; | ||
mod with_big_integer_left; | ||
mod with_empty_list_left; | ||
mod with_external_pid_left; | ||
mod with_float_left; | ||
mod with_heap_binary_left; | ||
mod with_list_left; | ||
mod with_local_pid_left; | ||
mod with_local_reference_left; | ||
mod with_map_left; | ||
mod with_small_integer_left; | ||
mod with_subbinary_left; | ||
mod with_tuple_left; | ||
|
||
fn is_equal_or_less_than<L, R>(left: L, right: R, expected: bool) | ||
where | ||
L: FnOnce(&mut Process) -> Term, | ||
R: FnOnce(Term, &mut Process) -> Term, | ||
{ | ||
with_process(|mut process| { | ||
let left = left(&mut process); | ||
let right = right(left, &mut process); | ||
|
||
assert_eq!( | ||
erlang::is_equal_or_less_than_2(left, right), | ||
expected.into() | ||
); | ||
}); | ||
} |
113 changes: 113 additions & 0 deletions
113
lumen_runtime/src/otp/erlang/tests/is_equal_or_less_than_2/with_atom_left.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use super::*; | ||
|
||
#[test] | ||
fn with_small_integer_right_returns_false() { | ||
is_equal_or_less_than(|_, mut process| 0.into_process(&mut process), false) | ||
} | ||
|
||
#[test] | ||
fn with_big_integer_right_returns_false() { | ||
is_equal_or_less_than( | ||
|_, mut process| (crate::integer::small::MAX + 1).into_process(&mut process), | ||
false, | ||
) | ||
} | ||
|
||
#[test] | ||
fn with_float_right_returns_false() { | ||
is_equal_or_less_than(|_, mut process| 0.0.into_process(&mut process), false) | ||
} | ||
|
||
#[test] | ||
fn with_lesser_atom_returns_false() { | ||
is_equal_or_less_than(|_, _| Term::str_to_atom("keft", DoNotCare).unwrap(), false); | ||
} | ||
|
||
#[test] | ||
fn with_same_atom_returns_true() { | ||
is_equal_or_less_than(|left, _| left, true); | ||
} | ||
|
||
#[test] | ||
fn with_same_atom_value_returns_true() { | ||
is_equal_or_less_than(|_, _| Term::str_to_atom("left", DoNotCare).unwrap(), true); | ||
} | ||
|
||
#[test] | ||
fn with_greater_atom_returns_true() { | ||
is_equal_or_less_than(|_, _| Term::str_to_atom("meft", DoNotCare).unwrap(), true); | ||
} | ||
|
||
#[test] | ||
fn with_local_reference_right_returns_true() { | ||
is_equal_or_less_than(|_, mut process| Term::local_reference(&mut process), true); | ||
} | ||
|
||
#[test] | ||
fn with_local_pid_right_returns_true() { | ||
is_equal_or_less_than(|_, _| Term::local_pid(0, 1).unwrap(), true); | ||
} | ||
|
||
#[test] | ||
fn with_external_pid_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| Term::external_pid(1, 2, 3, &mut process).unwrap(), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_tuple_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| Term::slice_to_tuple(&[], &mut process), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_map_right_returns_true() { | ||
is_equal_or_less_than(|_, mut process| Term::slice_to_map(&[], &mut process), true); | ||
} | ||
|
||
#[test] | ||
fn with_empty_list_right_returns_true() { | ||
is_equal_or_less_than(|_, _| Term::EMPTY_LIST, true); | ||
} | ||
|
||
#[test] | ||
fn with_list_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| { | ||
Term::cons( | ||
0.into_process(&mut process), | ||
1.into_process(&mut process), | ||
&mut process, | ||
) | ||
}, | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_heap_binary_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| Term::slice_to_binary(&[], &mut process), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_subbinary_right_returns_true() { | ||
is_equal_or_less_than(|_, mut process| bitstring!(1 :: 1, &mut process), true); | ||
} | ||
|
||
fn is_equal_or_less_than<R>(right: R, expected: bool) | ||
where | ||
R: FnOnce(Term, &mut Process) -> Term, | ||
{ | ||
super::is_equal_or_less_than( | ||
|_| Term::str_to_atom("left", DoNotCare).unwrap(), | ||
right, | ||
expected, | ||
); | ||
} |
137 changes: 137 additions & 0 deletions
137
lumen_runtime/src/otp/erlang/tests/is_equal_or_less_than_2/with_big_integer_left.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
use super::*; | ||
|
||
#[test] | ||
fn with_lesser_small_integer_right_returns_false() { | ||
is_equal_or_less_than(|_, mut process| 0.into_process(&mut process), false) | ||
} | ||
|
||
#[test] | ||
fn with_greater_small_integer_right_returns_true() { | ||
super::is_equal_or_less_than( | ||
|mut process| (crate::integer::small::MIN - 1).into_process(&mut process), | ||
|_, mut process| crate::integer::small::MIN.into_process(&mut process), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_lesser_big_integer_right_returns_false() { | ||
is_equal_or_less_than( | ||
|_, mut process| (crate::integer::small::MIN - 1).into_process(&mut process), | ||
false, | ||
) | ||
} | ||
|
||
#[test] | ||
fn with_same_big_integer_right_returns_true() { | ||
is_equal_or_less_than(|left, _| left, true) | ||
} | ||
|
||
#[test] | ||
fn with_same_value_big_integer_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| (crate::integer::small::MAX + 1).into_process(&mut process), | ||
true, | ||
) | ||
} | ||
|
||
#[test] | ||
fn with_greater_big_integer_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| (crate::integer::small::MAX + 2).into_process(&mut process), | ||
true, | ||
) | ||
} | ||
|
||
#[test] | ||
fn with_lesser_float_right_returns_false() { | ||
is_equal_or_less_than(|_, mut process| 0.0.into_process(&mut process), false) | ||
} | ||
|
||
#[test] | ||
fn with_greater_float_right_returns_true() { | ||
super::is_equal_or_less_than( | ||
|mut process| (crate::integer::small::MIN - 1).into_process(&mut process), | ||
|_, mut process| 0.0.into_process(&mut process), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_atom_right_returns_true() { | ||
is_equal_or_less_than(|_, _| Term::str_to_atom("right", DoNotCare).unwrap(), true); | ||
} | ||
|
||
#[test] | ||
fn with_local_reference_right_returns_true() { | ||
is_equal_or_less_than(|_, mut process| Term::local_reference(&mut process), true); | ||
} | ||
|
||
#[test] | ||
fn with_local_pid_right_returns_true() { | ||
is_equal_or_less_than(|_, _| Term::local_pid(0, 1).unwrap(), true); | ||
} | ||
|
||
#[test] | ||
fn with_external_pid_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| Term::external_pid(1, 2, 3, &mut process).unwrap(), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_tuple_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| Term::slice_to_tuple(&[], &mut process), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_map_right_returns_true() { | ||
is_equal_or_less_than(|_, mut process| Term::slice_to_map(&[], &mut process), true); | ||
} | ||
|
||
#[test] | ||
fn with_empty_list_right_returns_true() { | ||
is_equal_or_less_than(|_, _| Term::EMPTY_LIST, true); | ||
} | ||
|
||
#[test] | ||
fn with_list_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| { | ||
Term::cons( | ||
0.into_process(&mut process), | ||
1.into_process(&mut process), | ||
&mut process, | ||
) | ||
}, | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_heap_binary_right_returns_true() { | ||
is_equal_or_less_than( | ||
|_, mut process| Term::slice_to_binary(&[], &mut process), | ||
true, | ||
); | ||
} | ||
|
||
#[test] | ||
fn with_subbinary_right_returns_true() { | ||
is_equal_or_less_than(|_, mut process| bitstring!(1 :: 1, &mut process), true); | ||
} | ||
|
||
fn is_equal_or_less_than<R>(right: R, expected: bool) | ||
where | ||
R: FnOnce(Term, &mut Process) -> Term, | ||
{ | ||
super::is_equal_or_less_than( | ||
|mut process| (crate::integer::small::MAX + 1).into_process(&mut process), | ||
right, | ||
expected, | ||
); | ||
} |
Oops, something went wrong.