Fix tests

This commit is contained in:
2019-05-29 15:38:00 +02:00
parent ba0fca8755
commit 23cc193333
3 changed files with 27 additions and 16 deletions

View File

@@ -1,5 +1,7 @@
extern crate rustijvm;
use std::convert::TryInto;
fn steps(machine: &mut rustijvm::Machine, num: usize) {
for _ in 0..num {
machine.step().unwrap();
@@ -44,7 +46,9 @@ fn advancedstack_contents() {
let size = stack.len();
assert!(size >= 100);
let markers = (0..size).filter(|i| { stack.get(*i) == 0x2 }).count();
let markers = (0..size).filter(|i| {
stack.get(*i).try_into().unwrap_or(0) == 0x2
}).count();
assert!(markers >= 99);
}
@@ -55,7 +59,9 @@ fn advancedstack_method() {
steps(&mut machine, 8);
{
let stack = machine.cur_stack();
let markers = (0..stack.len()).filter(|i| { stack.get(*i) == 0x2 }).count();
let markers = (0..stack.len()).filter(|i| {
stack.get(*i).try_into().unwrap_or(0) == 0x2
}).count();
assert_eq!(markers, 4);
}
@@ -63,7 +69,9 @@ fn advancedstack_method() {
steps(&mut machine, 2 * 5000);
{
let stack = machine.cur_stack();
let markers = (0..stack.len()).filter(|i| { stack.get(*i) == 0x2 }).count();
let markers = (0..stack.len()).filter(|i| {
stack.get(*i).try_into().unwrap_or(0) == 0x2
}).count();
assert!(markers > 4000);
}
}