|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +from pytest import fixture |
| 5 | + |
| 6 | +from sigllm.data import sig2str, str2sig |
| 7 | + |
| 8 | + |
| 9 | +@fixture |
| 10 | +def integers(): |
| 11 | + return np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) |
| 12 | + |
| 13 | + |
| 14 | +@fixture |
| 15 | +def floats(): |
| 16 | + return np.array([ |
| 17 | + 1.283, |
| 18 | + 2.424, |
| 19 | + 3.213, |
| 20 | + 4.583, |
| 21 | + 5.486, |
| 22 | + 6.284, |
| 23 | + 7.297, |
| 24 | + 8.023, |
| 25 | + 9.786 |
| 26 | + ]) |
| 27 | + |
| 28 | + |
| 29 | +@fixture |
| 30 | +def text(): |
| 31 | + return '1,2,3,4,5,6,7,8,9' |
| 32 | + |
| 33 | + |
| 34 | +def test_sig2str(integers): |
| 35 | + expected = '1,2,3,4,5,6,7,8,9' |
| 36 | + |
| 37 | + result = sig2str(integers) |
| 38 | + |
| 39 | + assert result == expected |
| 40 | + |
| 41 | + |
| 42 | +def test_sig2str_decimal(integers): |
| 43 | + expected = '100,200,300,400,500,600,700,800,900' |
| 44 | + |
| 45 | + result = sig2str(integers, decimal=2) |
| 46 | + |
| 47 | + assert result == expected |
| 48 | + |
| 49 | + |
| 50 | +def test_sig2str_sep(integers): |
| 51 | + expected = '1|2|3|4|5|6|7|8|9' |
| 52 | + |
| 53 | + result = sig2str(integers, sep='|') |
| 54 | + |
| 55 | + assert result == expected |
| 56 | + |
| 57 | + |
| 58 | +def test_sig2str_space(integers): |
| 59 | + expected = '1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9' |
| 60 | + |
| 61 | + result = sig2str(integers, space=True) |
| 62 | + |
| 63 | + assert result == expected |
| 64 | + |
| 65 | + |
| 66 | +def test_sig2str_float(floats): |
| 67 | + expected = '1,2,3,4,5,6,7,8,9' |
| 68 | + |
| 69 | + result = sig2str(floats) |
| 70 | + |
| 71 | + assert result == expected |
| 72 | + |
| 73 | + |
| 74 | +def test_sig2str_float_decimal(floats): |
| 75 | + expected = '128,242,321,458,548,628,729,802,978' |
| 76 | + |
| 77 | + result = sig2str(floats, decimal=2) |
| 78 | + |
| 79 | + assert result == expected |
| 80 | + |
| 81 | + |
| 82 | +def test_str2sig(text): |
| 83 | + expected = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) |
| 84 | + |
| 85 | + result = str2sig(text) |
| 86 | + |
| 87 | + np.testing.assert_equal(result, expected) |
| 88 | + |
| 89 | + |
| 90 | +def test_str2sig_decimal(text): |
| 91 | + expected = np.array([.01, .02, .03, .04, .05, .06, .07, .08, .09]) |
| 92 | + |
| 93 | + result = str2sig(text, decimal=2) |
| 94 | + |
| 95 | + np.testing.assert_equal(result, expected) |
0 commit comments