Debian Codegraph @

test/uk/me/parabola/imgfmt/app/BitReaderTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2008 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 30-Nov-2008
16 */
17 package uk.me.parabola.imgfmt.app;
18
19 import org.junit.Test;
20
21 import static org.junit.Assert.*;
22
23
24 public class BitReaderTest {
25
26 /**
27 * Very simple test that the bit reader is working.
28 */
29 @Test
30 public void testGetBits() {
31 // Add your code here
32 BitReader br = new BitReader(new byte[]{
33 (byte) 0xf1, 0x73, (byte) 0xc2, 0x5
34 });
35
36 assertTrue("first bit", br.get1());
37 assertEquals("five bits", 0x18, br.get(5));
38 assertEquals("four bits", 0xf, br.get(4));
39 assertEquals("sixteen bits", 0x709c, br.get(16));
40 }
41
42 @Test
43 public void testSpecialNegative() {
44 BitReader br = new BitReader(new byte[]{0x24, 0xb});
45
46 int s = br.sget2(3);
47 assertEquals(-12, s);
48 }
49 @Test
50 public void testSpecialNegative2() {
51 BitReader br = new BitReader(new byte[]{0x2c, 0x0});
52
53 int s = br.sget2(3);
54 assertEquals(-6, s);
55 }
56
57 @Test
58 public void testSpecialPositive() {
59 BitReader br = new BitReader(new byte[]{(byte) 0xa4, 0});
60
61 int s = br.sget2(3);
62 assertEquals(8, s);
63 }
64
65 @Test
66 public void testWriteRead() {
67 for (int i = -20; i <= 20; i++){
68 BitWriter bw = new BitWriter();
69 bw.sputn(i,3);
70 BitReader br = new BitReader(bw.getBytes());
71
72 int s = br.sget2(3);
73 assertEquals(i, s);
74 }
75 }
76
77
78 }