Skip to content

Commit fae194b

Browse files
committed
Teste unitário para a classe InputBitStream
1 parent 763cf5b commit fae194b

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/main/java/core/bitstream/InputBitStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.security.InvalidParameterException;
66

77
/**
8-
* Classe com metodos para leitura de uma stream de bits
8+
* Classe com metodos para leitura de uma stream de bits.
99
*/
1010
public class InputBitStream {
1111

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package core.bitstream;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import static org.junit.jupiter.api.Assertions.*;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
11+
public class InputBitStreamTest {
12+
13+
private InputStream reader;
14+
private InputBitStream bstream;
15+
16+
@BeforeEach
17+
public void setUp() throws IOException {
18+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
19+
// 0000 0001 0000 0011 0000 0111 0000 1111 0001 1111
20+
baos.write(1);
21+
baos.write(3);
22+
baos.write(7);
23+
baos.write(15);
24+
baos.write(31);
25+
reader = new ByteArrayInputStream(baos.toByteArray());
26+
bstream = new InputBitStream(reader);
27+
}
28+
29+
@Test
30+
public void countWhileTest() throws IOException {
31+
// 1
32+
assertEquals(7, bstream.countWhile(false));
33+
assertEquals(0, bstream.countWhile(false));
34+
assertEquals(1, bstream.countWhile(true));
35+
assertEquals(0, bstream.countWhile(true));
36+
// 3
37+
assertEquals(6, bstream.countWhile(false));
38+
assertEquals(0, bstream.countWhile(false));
39+
assertEquals(2, bstream.countWhile(true));
40+
assertEquals(0, bstream.countWhile(true));
41+
// 7
42+
assertEquals(5, bstream.countWhile(false));
43+
assertEquals(0, bstream.countWhile(false));
44+
assertEquals(3, bstream.countWhile(true));
45+
assertEquals(0, bstream.countWhile(true));
46+
// 15
47+
assertEquals(4, bstream.countWhile(false));
48+
assertEquals(0, bstream.countWhile(false));
49+
assertEquals(4, bstream.countWhile(true));
50+
assertEquals(0, bstream.countWhile(true));
51+
// 31
52+
assertEquals(3, bstream.countWhile(false));
53+
assertEquals(0, bstream.countWhile(false));
54+
assertEquals(5, bstream.countWhile(true));
55+
assertEquals(0, bstream.countWhile(true));
56+
}
57+
58+
@Test
59+
public void nextTest() throws IOException {
60+
assertEquals(0, bstream.next(0));
61+
assertEquals(0, bstream.next(4));
62+
assertEquals(1, bstream.next(4));
63+
assertEquals(3, bstream.next(8));
64+
assertEquals(7, bstream.next(8));
65+
assertEquals(0, bstream.next(0));
66+
}
67+
}

0 commit comments

Comments
 (0)