Skip to content

Commit 8ba39a0

Browse files
committed
test: added a basic unit tests and one end-to-end integration test
1 parent 1656b07 commit 8ba39a0

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
File renamed without changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// Created by Inmoresentum on 1/20/25.
3+
//
4+
5+
#include <unity.h>
6+
#include <Arduino.h>
7+
#include <esp32_tflm_wrapper.h>
8+
#include "dummy_mlp_float32.h"
9+
10+
#define ARENA_SIZE 4700
11+
#define TF_NUM_OPS 2
12+
#define TF_NUM_INPUTS 13
13+
#define TF_NUM_OUTPUTS 4
14+
15+
Eloquent::TF::Sequential<TF_NUM_OPS, ARENA_SIZE> testMLP;
16+
17+
// Test inputs
18+
float test_inputs[] = {
19+
60.000000, 1.000000, 58.000000, 58.000000, 72.000000, 454.000000, 445.000000,
20+
23.000000, 30.000000, 10.000000, 219.000000, 255.000000, 446.000000
21+
};
22+
23+
void setUp(void) {
24+
// Initialize the model before each test
25+
testMLP.setNumInputs(TF_NUM_INPUTS);
26+
testMLP.setNumOutputs(TF_NUM_OUTPUTS);
27+
testMLP.resolver.AddFullyConnected();
28+
testMLP.resolver.AddSoftmax();
29+
TEST_ASSERT_TRUE(testMLP.begin(GeneratedCHeaderFile_simple_mlp_for_testing).isOk());
30+
}
31+
32+
void tearDown(void) {
33+
// Clean up after each test if needed
34+
}
35+
36+
void test_model_initialization() {
37+
TEST_ASSERT_EQUAL(TF_NUM_INPUTS, testMLP.numInputs);
38+
TEST_ASSERT_EQUAL(TF_NUM_OUTPUTS, testMLP.numOutputs);
39+
}
40+
41+
void test_prediction_success() {
42+
TEST_ASSERT_TRUE(testMLP.predict(test_inputs).isOk());
43+
}
44+
45+
void test_prediction_class() {
46+
testMLP.predict(test_inputs);
47+
TEST_ASSERT_EQUAL(2, testMLP.classification);
48+
}
49+
50+
void test_prediction_output_range() {
51+
testMLP.predict(test_inputs);
52+
// Check if all output probabilities are between 0 and 1
53+
for (u_int16_t i = 0; i < TF_NUM_OUTPUTS; i++) {
54+
TEST_ASSERT_TRUE(testMLP.outputs[i] >= 0.0f && testMLP.outputs[i] <= 1.0f);
55+
}
56+
}
57+
58+
void setup() {
59+
delay(2000); // Allow some time for board initialization
60+
UNITY_BEGIN();
61+
62+
RUN_TEST(test_model_initialization);
63+
RUN_TEST(test_prediction_success);
64+
RUN_TEST(test_prediction_class);
65+
RUN_TEST(test_prediction_output_range);
66+
67+
UNITY_END();
68+
}
69+
70+
void loop() {
71+
// Nothing to do here
72+
}

0 commit comments

Comments
 (0)