Skip to content
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Sep 19, 2018
1 parent de3b6e0 commit 8204e32
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 14 deletions.
15 changes: 15 additions & 0 deletions src/main/java/eu/kimb_technologies/usf/Atom.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
* @author kimbtech
*/
public abstract class Atom {

/**
* Exports the current data in this Atom to a parseable String.
* @return the parseable String
*/
public abstract String toUSF();

/**
* Imports data from an parseable Atom String.
* @param usf the String to parse
* @return the Atom data
* @throws USFSyntaxException thrown on Synatay errors
*/
public abstract Atom loadUSF( String usf ) throws USFSyntaxException;

@Override
public abstract boolean equals( Object o );
}
2 changes: 1 addition & 1 deletion src/main/java/eu/kimb_technologies/usf/Real.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Atom loadUSF(String usf) throws USFSyntaxException {

@Override
public int compareTo(Double o) {
return o.compareTo( this.val );
return ((Double) this.val).compareTo( o );
}

//Object
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/eu/kimb_technologies/usf/test/AtomTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package eu.kimb_technologies.usf.test;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import eu.kimb_technologies.usf.Atom;
import eu.kimb_technologies.usf.Bool;
import eu.kimb_technologies.usf.USFInteger;
import eu.kimb_technologies.usf.USFString;
import eu.kimb_technologies.usf.USFSyntaxException;

@DisplayName("USF Atom")
class AtomTest {

private Atom a1, a2, a3, a4;

@BeforeEach
public void setUp() throws Exception {
a1 = new USFInteger(12);
a2 = new USFInteger(12);
a3 = new USFInteger(223);
a4 = new USFString("aa");
}

@Test
@DisplayName("Equals Test")
public void testEquals() {
assertTrue( a1.equals( a2 ) );
assertFalse( a1.equals( a3 ) );
assertFalse( a1.equals( a4 ) );
assertFalse( a4.equals( new String("aa") ) );
}
}
21 changes: 11 additions & 10 deletions src/test/java/eu/kimb_technologies/usf/test/RealTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import eu.kimb_technologies.usf.Bool;
import eu.kimb_technologies.usf.Real;
import eu.kimb_technologies.usf.USFSyntaxException;

Expand Down Expand Up @@ -63,20 +64,21 @@ public void testLoadUSF() throws USFSyntaxException {
@Test
@DisplayName("USF Import Exception Test")
public void testLoadUSFEx(){
/*
assertThrows(USFSyntaxException.class,()->{
iNull.loadUSF("2");
iNull.loadUSF("2.0"); // should be =2.0=
});
assertThrows(USFSyntaxException.class,()->{
iNull.loadUSF("\"234\"");
iNull.loadUSF("*2");
});
assertThrows(USFSyntaxException.class,()->{
iNull.loadUSF(" 33 ");
iNull.loadUSF("234,12");
});
assertThrows(USFSyntaxException.class,()->{
iNull.loadUSF("33E2");
iNull.loadUSF(" 33- ");
});
assertThrows(USFSyntaxException.class,()->{
iNull.loadUSF("3.3.2");
});
*/
}

@Test
Expand All @@ -85,15 +87,14 @@ public void testEquals() throws USFSyntaxException {
assertTrue( iPlus.equals( new Real(100.110) ) );
assertFalse( iMinus.equals( new Real(-110.025) ) );
assertEquals( new Real(), iNull );
assertFalse( iMinus.equals( new Double(12.0) ) );
}

@Test
@DisplayName("Compare To Test")
public void testCompareTo() {
/*
assertEquals( iPlus.compareTo( new Integer(-100) ), (new Integer(100) ).compareTo( new Integer(-100) ) );
assertEquals( iMinus.compareTo( new Integer(-992) ), (new Integer(-992) ).compareTo( new Integer(-992) ) );
*/
assertEquals( iPlus.compareTo( new Double(-110) ), (new Double(100.110) ).compareTo( new Double(-110) ) );
assertEquals( iMinus.compareTo( new Double(-992) ), (new Double(-100.025) ).compareTo( new Double(-992) ) );
}

@Test
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/eu/kimb_technologies/usf/test/USFListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ public void testLoadUSF() {
});
}

@Test
@DisplayName("Equals")
public void testEquals() throws USFSyntaxException {
assertFalse( main.equals( new String("aa") ) );
assertFalse( main.equals( second ) );
main = (USFList) main.loadUSF("[{\"Haus\":[\"B\\\"lu\",{100:200},true]},2001,true,[true,true]]");
assertTrue( main.equals( second ) );
}

@Test
@DisplayName("implements List tests")
public void lists() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class USFParserTest {

@BeforeEach
public void setUp() throws Exception {
this.data = USFParser.parse("[true,false,100,20,-12,{\"test\":{\"a\":false}}]");
this.data = USFParser.parse("[true,false,100,20,-12,{\"test\":{\"a\":false}},=1.0=,=-11.02=]");
}

@Test
Expand All @@ -31,6 +31,8 @@ public void testParse() throws USFSyntaxException {
assertEquals(array[3], new USFInteger(20));
assertEquals(array[4], new USFInteger(-12));
assertEquals(array[5], new USFPair().loadUSF("{\"test\":{\"a\":false}}"));
assertEquals(array[6], new Real(1.0));
assertEquals(array[7], new Real(-11.02));
}

@Test
Expand All @@ -43,7 +45,7 @@ public void testFile() throws Exception {

Atom data = USFParser.loadFromFile(System.getProperty("user.home") + "/testfile.usf");

assertEquals( data.toUSF() , "[true,false,100,20,-12,{\"test\":{\"a\":false}}]");
assertEquals( data.toUSF() , "[true,false,100,20,-12,{\"test\":{\"a\":false}},=1.0=,=-11.02=]");

//delete test file
new File( System.getProperty("user.home") + "/testfile.usf" ).delete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void escapeTest() {
@DisplayName("USF Escape and Unescape Test")
public void unAndEscapeTest() {
String[] arr = {
"shdad \\ adfs",
"shdad \\ adfs \n",
"\"Hallo\" HHüüh \t \r dd++üä",
"FF_🇫🇷_FF",
"",
Expand Down

0 comments on commit 8204e32

Please sign in to comment.