$(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
#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;
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);
+++ /dev/null
-#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);
-}