From: Geoffrey Allott Date: Tue, 2 Aug 2022 07:48:13 +0000 (+0100) Subject: rename and combine tests X-Git-Url: https://git.pointlesshacks.com/?a=commitdiff_plain;h=ddd98dfbfc3edaeb30c867d96351b6e151933f98;p=tANS.git rename and combine tests --- diff --git a/Makefile b/Makefile index cfcbe1a..86ae62b 100644 --- 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 diff --git a/test/test_tans_encode_decode.c b/test/test_tANS.c similarity index 69% rename from test/test_tans_encode_decode.c rename to test/test_tANS.c index b6f67be..f551daf 100644 --- a/test/test_tans_encode_decode.c +++ b/test/test_tANS.c @@ -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 index d0e81eb..0000000 --- a/test/test_tans_encode_st.c +++ /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); -}