|
| 1 | +package eu.antidotedb.client.test; |
| 2 | + |
| 3 | +import com.google.protobuf.ByteString; |
| 4 | +import eu.antidotedb.client.ValueCoder; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.util.Random; |
| 8 | + |
| 9 | +import static org.junit.Assert.assertEquals; |
| 10 | + |
| 11 | +public class SimpleValueCoderTests { |
| 12 | + @Test |
| 13 | + public void integerCoder() { |
| 14 | + Random random = new Random(); |
| 15 | + for (int i = 0; i<1000; i++) { |
| 16 | + int orig = random.nextInt(); |
| 17 | + ByteString encoded = ValueCoder.integerCoder.encode(orig); |
| 18 | + int decoded = ValueCoder.integerCoder.decode(encoded); |
| 19 | + assertEquals(orig, decoded); |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + @Test |
| 24 | + public void longCoder() { |
| 25 | + Random random = new Random(); |
| 26 | + for (int i = 0; i<1000; i++) { |
| 27 | + long orig = random.nextLong(); |
| 28 | + ByteString encoded = ValueCoder.longCoder.encode(orig); |
| 29 | + long decoded = ValueCoder.longCoder.decode(encoded); |
| 30 | + assertEquals(orig, decoded); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void floatCoder() { |
| 36 | + Random random = new Random(); |
| 37 | + for (int i = 0; i<1000; i++) { |
| 38 | + float orig = random.nextFloat(); |
| 39 | + ByteString encoded = ValueCoder.floatCoder.encode(orig); |
| 40 | + float decoded = ValueCoder.floatCoder.decode(encoded); |
| 41 | + assertEquals(orig, decoded, 0.0001); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void doubleCoder() { |
| 47 | + Random random = new Random(); |
| 48 | + for (int i = 0; i<1000; i++) { |
| 49 | + double orig = random.nextDouble(); |
| 50 | + ByteString encoded = ValueCoder.doubleCoder.encode(orig); |
| 51 | + double decoded = ValueCoder.doubleCoder.decode(encoded); |
| 52 | + assertEquals(orig, decoded, 0.0001); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments