Skip to content

Commit

Permalink
update README and add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bruch-alex committed Jul 15, 2024
1 parent 337cd63 commit 8ea9af0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ Coder - [Coder.java](src%2Fmain%2FCoder.java)

Decoder - [Decoder.java](src%2Fmain%2FDecoder.java)

Methods that are used in the encoder and decoder - [Helpers.java](src%2Fmain%2FHelpers.java)
Methods that are used in the encoder and decoder - [Helpers.java](src%2Fmain%2FHelpers.java)

# How to run it?
1. You must have the JRE (minimum version 8) installed
2. Download latest [release-file.jar](https://github.com/bruch-alex/hamming-code/releases)
3. Open Terminal in directory, where you saved `.jar` file
4. Copy this command `java -cp hamming-code-VERSION-NUMBER.jar Main`, replace VERSION_NUMBER with current version and run it.
5. Just follow instructions on the screen :D
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.mycompany.app</groupId>
<artifactId>hamming-code</artifactId>
<version>1.0-SNAPSHOT</version>
<version>2024071400</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
Expand Down Expand Up @@ -41,7 +41,8 @@
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Main</mainClass>
</transformer>
</transformers>
Expand All @@ -58,6 +59,11 @@
<artifactId>jline</artifactId>
<version>3.26.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
2 changes: 1 addition & 1 deletion src/main/java/Coder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static String start(String message) {
* @param symbol symbol to convert
* @return binary string with 12 bits
*/
private static StringBuilder convertToBinaryWithParityBits(char symbol){
public static StringBuilder convertToBinaryWithParityBits(char symbol){
StringBuilder binaryString = new StringBuilder();
int val = symbol;
for (int i = 0; i < 12 ; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static String fixError(int y, String messageToFix) {
StringBuilder sb = new StringBuilder(messageToFix);
if (y != 0)
{
sb.replace(y-1,y,Helpers.changeBit(Character.digit(sb.charAt(y-1),10)));
sb.replace(y-1,y,String.valueOf(Helpers.changeBit(Character.digit(sb.charAt(y-1),10))));
}
return sb.toString();
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public static StringBuilder replaceParityBits(StringBuilder binaryMessageWithEmp
}

/**
*
* @param parityBitPosition - position of parity bit in message (starts with 0)
* @return value of parity bit (1 or 0)
*/
Expand Down Expand Up @@ -41,8 +40,8 @@ public static boolean checkPosition(int i){
* @param value binary value to be converted
* @return 1, if value is 0 and return 0, if value is 1.
*/
public static String changeBit(int value){
return (String.valueOf((value & 1) == 0 ? 1 : 0));
public static int changeBit(int value){
return (value & 1) == 0 ? 1 : 0;
}

}
Expand Down
19 changes: 18 additions & 1 deletion src/test/java/HelpersTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Test;

public class HelpersTest {

@Test
public void changeBitFrom1to0Test(){
Assert.assertEquals(1, Helpers.changeBit(0));
}

@Test
public void changeBitFrom0to1Test(){
Assert.assertEquals(0, Helpers.changeBit(1));
}

@Test
public void convertToBinaryWithParityBitsTestSymbol(){
StringBuilder sb = new StringBuilder("000011000001");
Assert.assertEquals(0, sb.compareTo(Coder.convertToBinaryWithParityBits('a')));
}

}

0 comments on commit 8ea9af0

Please sign in to comment.