rename and combine tests
authorGeoffrey Allott <geoffrey@allott.email>
Tue, 2 Aug 2022 07:48:13 +0000 (08:48 +0100)
committerGeoffrey Allott <geoffrey@allott.email>
Tue, 2 Aug 2022 07:48:13 +0000 (08:48 +0100)
Makefile
test/test_tANS.c [moved from test/test_tans_encode_decode.c with 69% similarity]
test/test_tans_encode_st.c [deleted file]

index cfcbe1a8172a4cc18ebfd2b1b2e8628b6c4161be..86ae62b3c838400e52e8cb1c47373a70036b6cf1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -16,8 +16,6 @@ all: $(OBJS)
 $(OBJS): %.o: %.h src/tans_constants.h
 $(TEST_OBJS): test/test.h $(OBJS)
 
-test/test_tans_encode_st.o: src/tans_encode_st.h src/tans_symbol_tbl.h src/tans_freq_tbl.h
-test/test_tans_encode_st: src/tans_encode_st.o src/tans_encode_tbl.o src/tans_symbol_tbl.o src/tans_freq_tbl.o
 test/test_tans_encode_decode.o: src/tans_decode_st.h src/tans_decode_tbl.h src/tans_encode_st.h src/tans_encode_tbl.h src/tans_symbol_tbl.h src/tans_freq_tbl.h
 test/test_tans_encode_decode: src/tans_decode_st.o src/tans_decode_tbl.o src/tans_encode_st.o src/tans_encode_tbl.o src/tans_symbol_tbl.o src/tans_freq_tbl.o
 
similarity index 69%
rename from test/test_tans_encode_decode.c
rename to test/test_tANS.c
index b6f67bed89e8abfe060bf4b1fd7919f3c3c760bf..f551daffd32b7d0f099281dc7c24e26afea37ba2 100644 (file)
@@ -4,6 +4,52 @@
 #include "tans_decode_st.h"
 #include "tans_encode_st.h"
 
+enum test_result test_tans_encode_equal_freq(void)
+{
+    struct tans_freq_tbl freq_tbl;
+    struct tans_symbol_tbl symbol_tbl;
+    struct tans_encode_st encode_st;
+    uint8_t data[8] = {0x01, 0xfe, 0x32, 0x12, 0x06, 0x07, 0x88, 0x00};
+    double p[256];
+    uint8_t buf[4 + 8 + 4] = {0};
+    uint16_t i;
+    uint16_t n_symbols = 256;
+    uint16_t log2_tblsz = 10;
+
+    for (i = 0; i < n_symbols; ++i) p[i] = 1.0 / n_symbols;
+    ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1);
+    ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0);
+    tans_encode_st_init(&encode_st, &symbol_tbl);
+
+    ASSERT_EQ(tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4), sizeof data * 8);
+
+
+    return TEST_SUCCESS;
+}
+
+enum test_result test_tans_encode_high_zero_probability(void)
+{
+    struct tans_freq_tbl freq_tbl;
+    struct tans_symbol_tbl symbol_tbl;
+    struct tans_encode_st encode_st;
+    uint8_t data[8] = {0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x23};
+    double p[256];
+    uint8_t buf[16] = {0};
+    uint16_t i;
+    uint16_t n_symbols = 256;
+    uint16_t log2_tblsz = 12;
+
+    p[0] = 0.75;
+    for (i = 1; i < n_symbols; ++i) p[i] = 0.25 / n_symbols;
+    ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1);
+    ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0);
+    tans_encode_st_init(&encode_st, &symbol_tbl);
+
+    ASSERT_LT(tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4), 24);
+
+    return TEST_SUCCESS;
+}
+
 enum test_result test_tans_encode_decode_equal_freq(void)
 {
     struct tans_freq_tbl freq_tbl;
@@ -111,6 +157,8 @@ enum test_result test_tans_encode_decode_long_stream(void)
 
 int main(void)
 {
+    RUN_TEST(test_tans_encode_equal_freq);
+    RUN_TEST(test_tans_encode_high_zero_probability);
     RUN_TEST(test_tans_encode_decode_equal_freq);
     RUN_TEST(test_tans_encode_decode_high_zero_probability);
     RUN_TEST(test_tans_encode_decode_long_stream);
diff --git a/test/test_tans_encode_st.c b/test/test_tans_encode_st.c
deleted file mode 100644 (file)
index d0e81eb..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "test.h"
-
-#include "floor_log2.h"
-#include "tans_encode_st.h"
-
-enum test_result test_tans_encode_st_equal_freq(void)
-{
-    struct tans_freq_tbl freq_tbl;
-    struct tans_symbol_tbl symbol_tbl;
-    struct tans_encode_st encode_st;
-    uint8_t data[8] = {0x01, 0xfe, 0x32, 0x12, 0x06, 0x07, 0x88, 0x00};
-    double p[256];
-    uint8_t buf[4 + 8 + 4] = {0};
-    uint16_t i;
-    uint16_t n_symbols = 256;
-    uint16_t log2_tblsz = 10;
-
-    for (i = 0; i < n_symbols; ++i) p[i] = 1.0 / n_symbols;
-    ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1);
-    ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0);
-    tans_encode_st_init(&encode_st, &symbol_tbl);
-
-    ASSERT_EQ(tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4), sizeof data * 8);
-
-
-    return TEST_SUCCESS;
-}
-
-enum test_result test_tans_encode_st_high_zero_probability(void)
-{
-    struct tans_freq_tbl freq_tbl;
-    struct tans_symbol_tbl symbol_tbl;
-    struct tans_encode_st encode_st;
-    uint8_t data[8] = {0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x23};
-    double p[256];
-    uint8_t buf[16] = {0};
-    uint16_t i;
-    uint16_t n_symbols = 256;
-    uint16_t log2_tblsz = 12;
-
-    p[0] = 0.75;
-    for (i = 1; i < n_symbols; ++i) p[i] = 0.25 / n_symbols;
-    ASSERT_NE(tans_freq_tbl_init(&freq_tbl, n_symbols, p, log2_tblsz), -1);
-    ASSERT_EQ(tans_symbol_tbl_init(&symbol_tbl, &freq_tbl), 0);
-    tans_encode_st_init(&encode_st, &symbol_tbl);
-
-    ASSERT_LT(tans_encode_st_encode(&encode_st, data, sizeof data, buf + 4), 24);
-
-    return TEST_SUCCESS;
-}
-
-int main(void)
-{
-    RUN_TEST(test_tans_encode_st_equal_freq);
-    RUN_TEST(test_tans_encode_st_high_zero_probability);
-}