-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpuOpcodeAddTest.h
49 lines (36 loc) · 1.02 KB
/
cpuOpcodeAddTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef CPUOPCODETEST_H
#define CPUOPCODETEST_H
#include "common.h"
#include "dcpu.h"
TEST(cpu_opcode_add_test, add_A_B_will_compute_A_plus_B)
{
const int arg1 = 0x0010;
const int arg2 = 0x0020;
word memory[memorySize] = {0x0402};
word reg[NUMBEROFREGISTERS] = {arg1, arg2};
DCPU cpu(memory, reg);
cpu.execute();
ASSERT_TRUE(reg[A] == arg1+arg2);
}
TEST(cpu_opcode_add_test, add_A_B_of_large_values_will_set_the_overflow_flag)
{
const int arg1 = 0xFFFF;
const int arg2 = 0x0001;
word memory[memorySize] = {0x0402};
word reg[NUMBEROFREGISTERS] = {arg1, arg2};
DCPU cpu(memory, reg);
cpu.execute();
ASSERT_TRUE(reg[O] == 1);
}
TEST(cpu_opcode_add_test, add_A_B_of_small_values_will_set_the_overflow_flag_to_false)
{
const int arg1 = 0x00FF;
const int arg2 = 0x0001;
word memory[memorySize] = {0x0402};
word reg[NUMBEROFREGISTERS] = {arg1, arg2};
reg[O] = 1;
DCPU cpu(memory, reg);
cpu.execute();
ASSERT_TRUE(reg[O] == 0);
}
#endif // CPUOPCODETEST_H