MCPcopy Create free account
hub / github.com/IntegralPilot/wasm_os / main

Function main

apps/vec-test-cpp/src/main.cpp:7–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <new.hpp> // for std::badalloc
6
7int main() {
8 std::cout << "WasmOS C++ STDLIB Vector Test" << std::endl;
9
10 std::srand(std::time(nullptr));
11
12 // generate 10 random numbers to use in our testing
13 std::vector<int> original_numbers;
14 for (int i = 0; i < 10; i++) {
15 original_numbers.push_back(std::rand() % 100);
16 }
17
18 std::vector<int> numbers;
19
20 // test push_back
21 for (int i = 0; i < 10; i++) {
22 numbers.push_back(original_numbers[i]);
23 }
24
25 // check if the numbers are the same
26 for (int i = 0; i < 10; i++) {
27 if (numbers[i] != original_numbers[i]) {
28 std::cout << "Error: numbers[" << i << "] = " << numbers[i] << " != " << original_numbers[i] << std::endl;
29 return 1;
30 }
31 }
32
33 std::cout << "Push back test passed" << std::endl;
34
35 // test pop_back
36 for (int i = 0; i < 10; i++) {
37 numbers.pop_back();
38 }
39
40 // check if the vector is empty
41 if (!numbers.empty()) {
42 std::cout << "Error: vector is not empty after calling pop_back 10 times" << std::endl;
43 return 1;
44 }
45
46 std::cout << "Pop back test passed" << std::endl;
47
48 // test reserve
49 numbers.reserve(10);
50 if (numbers.capacity() < 10) {
51 std::cout << "Error: capacity is less than 10 after calling reserve(10)" << std::endl;
52 return 1;
53 }
54
55 std::cout << "Reserve test passed" << std::endl;
56
57 // test resize
58 numbers.resize(10);
59 if (numbers.size() != 10) {
60 std::cout << "Error: size is not 10 after calling resize(10)" << std::endl;
61 return 1;
62 }
63
64 std::cout << "Resize test passed" << std::endl;

Callers 1

_startFunction · 0.70

Calls 15

push_backMethod · 0.80
pop_backMethod · 0.80
emptyMethod · 0.80
reserveMethod · 0.80
capacityMethod · 0.80
resizeMethod · 0.80
clearMethod · 0.80
insertMethod · 0.80
eraseMethod · 0.80
srandFunction · 0.50
timeFunction · 0.50
randFunction · 0.50

Tested by

no test coverage detected