Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: la3lma/chordguesser
base: 7a47bde672
...
head fork: la3lma/chordguesser
compare: 589badd530
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
10 pom.xml
@@ -11,7 +11,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ <version>4.0</version>
<scope>test</scope>
</dependency>
@@ -24,14 +24,6 @@
<!--
-
- <dependency>
- <groupId>junit</groupId>
- <version>4.0</version>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
View
13 src/main/java/com/mycompany/app/App.java
@@ -1,13 +0,0 @@
-package com.mycompany.app;
-
-/**
- * Hello world!
- *
- */
-public class App
-{
- public static void main( String[] args )
- {
- System.out.println( "Hello World!" );
- }
-}
View
43 src/main/java/no/rmz/chordguesser/BitVector.java
@@ -17,7 +17,7 @@
/**
* The number of bits.
*/
- private final int length;
+ private final int lengthInBits;
/**
* The eight-bit bytes that holds the bits.
@@ -25,15 +25,32 @@
*/
private final byte [] bytes;
+
+ /**
+ * Throw an IllegalArgumentException if the
+ * parameter is not a valid index into a bit.
+ * @param bit
+ */
+ private void checkArg(final int bit) {
+ if (bit < 0) {
+ throw new IllegalArgumentException("Index less than zero");
+ } else if (bit >= lengthInBits) {
+ throw new IllegalArgumentException("Index larger than length (" + lengthInBits + ")");
+ }
+ }
+
/**
* Create a bitvector with a length specified as number of
* significant bits. The bits are addressed in the range
- * 0 .. (length-1)
- * @param l
+ * 0 .. (lengthInBits-1)
+ * @param noOfBits
*/
- public BitVector(final int l) {
- this.length = l;
- this.bytes = new byte[(l / NO_OF_BITS_IN_A_BYTE) + 1];
+ public BitVector(final int noOfBits) {
+ if (noOfBits < 1) {
+ throw new IllegalArgumentException("No of bits less than one");
+ }
+ this.lengthInBits = noOfBits;
+ this.bytes = new byte[(noOfBits / NO_OF_BITS_IN_A_BYTE) + 1];
}
/**
@@ -42,6 +59,7 @@ public BitVector(final int l) {
* @param bit the bit to set.
*/
public void set(final int bit) {
+ checkArg(bit);
int by = bit / NO_OF_BITS_IN_A_BYTE;
int bi = bit % NO_OF_BITS_IN_A_BYTE;
bytes[by] = (byte) (bytes[by] | (1 << bi));
@@ -53,8 +71,21 @@ public void set(final int bit) {
* @param bit the bit to clear.
*/
public void unset(final int bit) {
+ checkArg(bit);
int by = bit / NO_OF_BITS_IN_A_BYTE;
int bi = bit % NO_OF_BITS_IN_A_BYTE;
bytes[by] = (byte) (bytes[by] & ~(1 << bi));
}
+
+ /**
+ * Set the bit no "bit" to 0.
+ *
+ * @param bit the bit to clear.
+ */
+ public boolean read(final int bit) {
+ checkArg(bit);
+ int by = bit / NO_OF_BITS_IN_A_BYTE;
+ int bi = bit % NO_OF_BITS_IN_A_BYTE;
+ return 0 != (bytes[by] & (1 << bi));
+ }
}
View
38 src/test/java/com/mycompany/app/AppTest.java
@@ -1,38 +0,0 @@
-package com.mycompany.app;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
-}

No commit comments for this range

Something went wrong with that request. Please try again.