Skip to content

Commit

Permalink
Improved automated tests. Updates dependencies/plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Apr 17, 2023
1 parent 1c194c9 commit eb2e759
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 73 deletions.
22 changes: 17 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.fross</groupId>
<artifactId>rpncalc</artifactId>
<version>4.7.5</version>
<version>4.7.6</version>
<packaging>jar</packaging>

<name>rpncalc</name>
Expand Down Expand Up @@ -46,13 +46,25 @@
</resources>

<plugins>
<plugin>
<!-- ========================================================================================== -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-resources-plugin -->
<!-- ========================================================================================== -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<propertiesEncoding>${project.build.sourceEncoding}</propertiesEncoding>
</configuration>
</plugin>

<plugin>
<!-- ========================================================================================== -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<!-- ========================================================================================== -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.11.0</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
Expand All @@ -65,7 +77,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.0.0</version>
</plugin>

<!-- ========================================================================================== -->
Expand All @@ -75,7 +87,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -132,7 +144,7 @@

<!-- ============================================================================================== -->
<!-- Update snapcraft.yaml file to set the program and library versions -->
<!-- https://mvnrepository.com/artifact/com.google.code.maven-replacer-plugin/maven-replacer-plugin -->
<!-- https://code.google.com/archive/p/maven-replacer-plugin/ -->
<!-- ============================================================================================== -->
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rpncalc
version: '4.7.5'
version: '4.7.6'
summary: The command line Reverse Polish Notation (RPN) calculator
description: |
RPNCalc is an easy to use command line based Reverse Polish
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fross/rpncalc/CommandLineArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void ProcessCommandLine(String[] argv) {

// Version Display
if (cli.clVersion == true) {
Main.DisplayVersion();
Help.DisplayVersion();
System.exit(0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fross/rpncalc/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public static void Parse(StackObj calcStack, StackObj calcStack2, String cmdInpu
// Version
case "ver":
case "version":
Main.DisplayVersion();
Help.DisplayVersion();
break;

// Help
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/fross/rpncalc/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package org.fross.rpncalc;

import org.fross.library.Format;
import org.fross.library.GitHub;
import org.fross.library.Output;
import org.fusesource.jansi.Ansi;

Expand Down Expand Up @@ -149,6 +150,17 @@ public static void Display() {

}

/**
* Display Version(): Show the program version, copyright, and latest GitHub release
*
*/
public static void DisplayVersion() {
Output.printColorln(Ansi.Color.WHITE, "RPNCalc Version: v" + Main.VERSION);
Output.printColorln(Ansi.Color.CYAN, Main.COPYRIGHT);
Output.printColorln(Ansi.Color.WHITE, "\nLatest Release on GitHub: " + GitHub.updateCheck("rpncalc"));
Output.printColorln(Ansi.Color.CYAN, "HomePage: https://github.com/frossm/rpncalc");
}

/**
* DisplayLicense(): Simply display the software usage license and return
*
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/org/fross/rpncalc/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import org.fross.library.Debug;
import org.fross.library.Format;
import org.fross.library.GitHub;
import org.fross.library.Output;
import org.fusesource.jansi.Ansi;
import org.jline.reader.LineReader;
Expand Down Expand Up @@ -67,17 +66,6 @@ public class Main {
static int configMemorySlots = CONFIG_DEFAULT_MEMORY_SLOTS;
static String configAlignment = CONFIG_DEFAULT_ALIGNMENT;

/**
* Display Version(): Show the program version, copyright, and latest GitHub release
*
*/
public static void DisplayVersion() {
Output.printColorln(Ansi.Color.WHITE, "RPNCalc Version: v" + Main.VERSION);
Output.printColorln(Ansi.Color.CYAN, Main.COPYRIGHT);
Output.printColorln(Ansi.Color.WHITE, "\nLatest Release on GitHub: " + GitHub.updateCheck("rpncalc"));
Output.printColorln(Ansi.Color.CYAN, "HomePage: https://github.com/frossm/rpncalc");
}

/**
* DisplayStatusLine(): Display the last line of the header and the separator line. This is a separate function given it also
* inserts the loaded stack and spaces everything correctly.
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/org/fross/rpncalc/CommandLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
*
*/
class CommandLineArgsTest {

/**
* Test method for {@link org.fross.rpncalc.CommandLineArgs#ProcessCommandLine(java.lang.String[])}.
*/
@Test
void testShortCommandLineArgs() {
// Test Short Options
Expand Down
84 changes: 63 additions & 21 deletions src/test/java/org/fross/rpncalc/CommandParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,90 @@
class CommandParserTest {

/**
* Test method for
* {@link org.fross.rpncalc.CommandParser#Parse(org.fross.rpncalc.StackObj, org.fross.rpncalc.StackObj, java.lang.String, java.lang.String, java.lang.String)}.
*
* Parser is just a big switch statement and takes commands entered and runs the specific method. The key part to test is the
* 'default:' portion where numbers, fractions, or NumOps are entered
* 'default:' portion where numbers, fractions, and NumOps are entered
*
*/
**/

// Test standard number inputs
@Test
void testParsingOfNumbersFractionsNumOp() {
void testNormalNumberEntry() {
StackObj stk1 = new StackObj();
StackObj stk2 = new StackObj();

// Standard numbers
// Fraction Input
stk1.clear();
CommandParser.Parse(stk1, stk2, "123", "123", "");
assertEquals(123, stk1.get(0));
assertEquals(1, stk1.size());

CommandParser.Parse(stk1, stk2, "123", "123", "");
CommandParser.Parse(stk1, stk2, "456.789", "456.789", "");
assertEquals(123, stk1.get(0));
assertEquals(2, stk1.size());

// Swap the stack and the size should be 0
CommandParser.Parse(stk1, stk2, "ss", "ss", "");
assertEquals(0, stk1.size());
CommandParser.Parse(stk1, stk2, "123", "123", "");
assertEquals(123, stk1.get(0));
assertEquals(3, stk1.size());
}

// Swap it back and we should be at 2 again
CommandParser.Parse(stk1, stk2, "ss", "ss", "");
assertEquals(2, stk1.size());
// Test fractional inputs
@Test
void testFractionInput() {
StackObj stk1 = new StackObj();
StackObj stk2 = new StackObj();

// Fraction Input
stk1.clear();
CommandParser.Parse(stk1, stk2, "1/8", "1/8", "");
assertEquals(.125, stk1.peek());
assertEquals(1, stk1.size());
assertEquals(.125, stk1.get(0));

// NumOp
CommandParser.Parse(stk1, stk2, "47/88", "47/88", "");
assertEquals(0.5340909090909091, stk1.peek());
assertEquals(2, stk1.size());

CommandParser.Parse(stk1, stk2, "1 3/16", "1", "3/16");
assertEquals(1.1875, stk1.peek());
assertEquals(3, stk1.size());

CommandParser.Parse(stk1, stk2, "-4 1/64", "-4", "1/64");
assertEquals(-3.984375, stk1.peek());
assertEquals(4, stk1.size());
}

@Test
void testNumOp() {
StackObj stk1 = new StackObj();
StackObj stk2 = new StackObj();

stk1.clear();
CommandParser.Parse(stk1, stk2, "123", "123", "");
CommandParser.Parse(stk1, stk2, "-123.456", "-123.456", "");
assertEquals(1, stk1.size());
assertEquals(-123.456, stk1.peek());

CommandParser.Parse(stk1, stk2, "2+", "2+", "");
CommandParser.Parse(stk1, stk2, "16-", "16-", "");
CommandParser.Parse(stk1, stk2, "2*", "2*", "");
assertEquals(1, stk1.size());
assertEquals(-121.456, stk1.peek());

CommandParser.Parse(stk1, stk2, "16.61-", "16.61-", "");
assertEquals(1, stk1.size());
assertEquals(-138.066, stk1.peek());

CommandParser.Parse(stk1, stk2, "-2.2*", "-2.2*", "");
assertEquals(1, stk1.size());
assertEquals(303.7452, stk1.peek());

CommandParser.Parse(stk1, stk2, "10/", "10/", "");
CommandParser.Parse(stk1, stk2, ".12^", ".12^", "");
assertEquals(1, stk1.size());
assertEquals(30.37452, stk1.peek());

CommandParser.Parse(stk1, stk2, "2^", "2^", "");
assertEquals(1, stk1.size());
assertEquals(922.6114652304, stk1.peek());

assertEquals(1, stk1.size());
StackCommands.cmdRound(stk1, "5");
assertEquals(1.44749, stk1.get(0));
assertEquals(922.61147, stk1.peek());
}

}
25 changes: 11 additions & 14 deletions src/test/java/org/fross/rpncalc/ConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,16 @@

class ConfigurationTest {

/**
* Testing the various 'set' commands
*
* 'reset' tested here as well
*/
@Test
void testCmdSetMemSlots() {
Preferences prefConfig = Preferences.userRoot().node("/org/fross/rpn/config");
// Class variables
Preferences prefConfig = Preferences.userRoot().node("/org/fross/rpn/config");

// Save current settings so they can be reinstated after the test
String align = prefConfig.get("alignment", Main.CONFIG_DEFAULT_ALIGNMENT);
int width = prefConfig.getInt("programwidth", Main.CONFIG_DEFAULT_PROGRAM_WIDTH);
int memSlots = prefConfig.getInt("memoryslots", Main.CONFIG_DEFAULT_MEMORY_SLOTS);
// Save current settings so they can be reinstated after the test
String align = prefConfig.get("alignment", Main.CONFIG_DEFAULT_ALIGNMENT);
int width = prefConfig.getInt("programwidth", Main.CONFIG_DEFAULT_PROGRAM_WIDTH);
int memSlots = prefConfig.getInt("memoryslots", Main.CONFIG_DEFAULT_MEMORY_SLOTS);

@Test
void testCmdSetMemSlots() {
// Test MemSlots
Configuration.cmdSet("memslots 1123");
assertEquals(1123, StackMemory.memorySlots.length);
Expand Down Expand Up @@ -87,7 +83,10 @@ void testCmdSetMemSlots() {
Configuration.cmdSet("align L");
assertEquals("l", Main.configAlignment);
assertEquals("l", prefConfig.get("alignment", ""));
}

@Test
void testResetCommand() {
// Test Reset
Configuration.cmdReset();
assertEquals(Main.CONFIG_DEFAULT_PROGRAM_WIDTH, Main.configProgramWidth);
Expand All @@ -104,7 +103,5 @@ void testCmdSetMemSlots() {
prefConfig.put("alignment", align);
prefConfig.putInt("memoryslots", memSlots);
}



}
Loading

0 comments on commit eb2e759

Please sign in to comment.