-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog2.cpp
More file actions
30 lines (22 loc) · 791 Bytes
/
log2.cpp
File metadata and controls
30 lines (22 loc) · 791 Bytes
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
#include <catch.hpp>
#include <assembler.h>
#include <cmath>
TEST_CASE("Log2 ASM")
{
using namespace std::chrono_literals;
auto buffer = std::stringstream();
auto assembly_input = std::ifstream("lib/tests/integration/log2.laval", std::ios::in | std::ios::binary);
Assembler::preprocess(assembly_input, buffer);
auto [ast, settings] = Assembler::parse(buffer);
auto output = std::stringstream();
output.seekg(0);
Assembler::assemble(ast, settings, output);
auto cpu = Assembler::load_binary(output);
for (auto a = 5_u8; a < 0xff_u8; a++)
{
std::istringstream input(std::to_string(a));
auto answer = static_cast<int>(cpu.start(input, std::cout));
INFO(a);
REQUIRE(answer == std::floor(std::log2(a)));
}
}