Skip to content

Commit

Permalink
JACOBIN-300 Added tests for IF_ICMPEQ, when two ints are not equal..
Browse files Browse the repository at this point in the history
  • Loading branch information
platypusguy committed Jul 28, 2023
1 parent 15e7c7f commit 1929a97
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/jvm/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2400,6 +2400,29 @@ func TestIfIcmpeq(t *testing.T) {
}
}

// IF_ICMPEQ: jump if val1 == val2; here test with unequal value
func TestIfIcmpeqUnequal(t *testing.T) {
f := newFrame(IF_ICMPEQ)
push(&f, int64(9)) // pushed two unequal values, so no jump should be made.
push(&f, int64(-9))

fs := frames.CreateFrameStack()
fs.PushFront(&f) // push the new frame
err := runFrame(fs)

if err != nil {
t.Errorf("IF_ICMPEQ: Got unexpected error: %s", err.Error())
}

if f.PC != 3 { // 2 for the jump due to inequality above, +1 for fetch of next bytecode
t.Errorf("IF_ICMPEQ: Expected PC to be 2, got %d", f.PC)
}

if f.TOS != -1 { // stack should be empty
t.Errorf("IF_CIMPEQ: Expected an empty stack, got TOS of: %d", f.TOS)
}
}

// IF_CMPGE: if integer compare val 1 >= val 2. Here test for = (next test for >)
func TestIfIcmpge1(t *testing.T) {
f := newFrame(IF_ICMPGE)
Expand Down

0 comments on commit 1929a97

Please sign in to comment.