diff --git a/pom.xml b/pom.xml
index 05b717c..3e5685f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
org.fross
rpncalc
- 4.7.5
+ 4.7.6
jar
rpncalc
@@ -46,13 +46,25 @@
+
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.3.0
+
+ ${project.build.sourceEncoding}
+
+
+
org.apache.maven.plugins
maven-compiler-plugin
- 3.10.1
+ 3.11.0
${maven.compiler.release}
@@ -65,7 +77,7 @@
org.apache.maven.plugins
maven-surefire-plugin
- 3.0.0-M7
+ 3.0.0
@@ -75,7 +87,7 @@
org.apache.maven.plugins
maven-shade-plugin
- 3.3.0
+ 3.4.1
package
@@ -132,7 +144,7 @@
-
+
com.google.code.maven-replacer-plugin
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index 6f35712..47cc86f 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -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
diff --git a/src/main/java/org/fross/rpncalc/CommandLineArgs.java b/src/main/java/org/fross/rpncalc/CommandLineArgs.java
index 17405cc..44a6891 100644
--- a/src/main/java/org/fross/rpncalc/CommandLineArgs.java
+++ b/src/main/java/org/fross/rpncalc/CommandLineArgs.java
@@ -92,7 +92,7 @@ public static void ProcessCommandLine(String[] argv) {
// Version Display
if (cli.clVersion == true) {
- Main.DisplayVersion();
+ Help.DisplayVersion();
System.exit(0);
}
diff --git a/src/main/java/org/fross/rpncalc/CommandParser.java b/src/main/java/org/fross/rpncalc/CommandParser.java
index f1120ed..73af50b 100644
--- a/src/main/java/org/fross/rpncalc/CommandParser.java
+++ b/src/main/java/org/fross/rpncalc/CommandParser.java
@@ -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
diff --git a/src/main/java/org/fross/rpncalc/Help.java b/src/main/java/org/fross/rpncalc/Help.java
index 961f647..4bc38d5 100644
--- a/src/main/java/org/fross/rpncalc/Help.java
+++ b/src/main/java/org/fross/rpncalc/Help.java
@@ -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;
@@ -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
*
diff --git a/src/main/java/org/fross/rpncalc/Main.java b/src/main/java/org/fross/rpncalc/Main.java
index fca8a94..8f0f219 100644
--- a/src/main/java/org/fross/rpncalc/Main.java
+++ b/src/main/java/org/fross/rpncalc/Main.java
@@ -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;
@@ -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.
diff --git a/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java b/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java
index acefe27..9e65992 100644
--- a/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java
+++ b/src/test/java/org/fross/rpncalc/CommandLineArgsTest.java
@@ -39,10 +39,6 @@
*
*/
class CommandLineArgsTest {
-
- /**
- * Test method for {@link org.fross.rpncalc.CommandLineArgs#ProcessCommandLine(java.lang.String[])}.
- */
@Test
void testShortCommandLineArgs() {
// Test Short Options
diff --git a/src/test/java/org/fross/rpncalc/CommandParserTest.java b/src/test/java/org/fross/rpncalc/CommandParserTest.java
index 5512b4a..88d6a8a 100644
--- a/src/test/java/org/fross/rpncalc/CommandParserTest.java
+++ b/src/test/java/org/fross/rpncalc/CommandParserTest.java
@@ -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());
}
}
diff --git a/src/test/java/org/fross/rpncalc/ConfigurationTest.java b/src/test/java/org/fross/rpncalc/ConfigurationTest.java
index 975116b..b899cbf 100644
--- a/src/test/java/org/fross/rpncalc/ConfigurationTest.java
+++ b/src/test/java/org/fross/rpncalc/ConfigurationTest.java
@@ -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);
@@ -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);
@@ -104,7 +103,5 @@ void testCmdSetMemSlots() {
prefConfig.put("alignment", align);
prefConfig.putInt("memoryslots", memSlots);
}
-
-
}
diff --git a/src/test/java/org/fross/rpncalc/MathTest.java b/src/test/java/org/fross/rpncalc/MathTest.java
index 22242e0..6851443 100644
--- a/src/test/java/org/fross/rpncalc/MathTest.java
+++ b/src/test/java/org/fross/rpncalc/MathTest.java
@@ -49,7 +49,6 @@ void testAdd() {
// Add test data to stack
stk.push(1.23456);
stk.push(4.56789);
-
assertEquals(5.80245, Math.Parse("+", stk).peek());
assertEquals(1, stk.size());
@@ -58,7 +57,7 @@ void testAdd() {
StackCommands.cmdRound(stk, "5");
assertEquals(4.70245, stk.peek());
assertEquals(1, stk.size());
- };
+ }
/**
* Test method for {@link org.fross.rpncalc.Math#Subtract(org.fross.rpncalc.StackObj)}.
@@ -70,9 +69,20 @@ void testSubtract() {
// Add test data to stack
stk.push(1.23456);
stk.push(4.56789);
-
assertEquals(-3.33333, Math.Parse("-", stk).peek());
assertEquals(1, stk.size());
+
+ stk.push(-3.12);
+ Math.Parse("-", stk);
+ StackCommands.cmdRound(stk, "5");
+ assertEquals(-0.21333, stk.peek());
+ assertEquals(1, stk.size());
+
+ stk.push(6.678);
+ Math.Parse("-", stk);
+ StackCommands.cmdRound(stk, "5");
+ assertEquals(-6.89133, stk.peek());
+ assertEquals(1, stk.size());
}
/**
@@ -85,10 +95,14 @@ void testMultiply() {
// Add test data to stack
stk.push(1.23456);
stk.push(4.56789);
-
Math.Parse("*", stk);
StackCommands.cmdRound(stk, "5");
assertEquals(5.63933, stk.peek());
+
+ stk.push(-99.88);
+ Math.Parse("*", stk);
+ StackCommands.cmdRound(stk, "5");
+ assertEquals(-563.25628, stk.peek());
assertEquals(1, stk.size());
}
@@ -102,10 +116,14 @@ void testDivide() {
// Add test data to stack
stk.push(1.23456);
stk.push(4.56789);
-
Math.Parse("/", stk);
StackCommands.cmdRound(stk, "5");
assertEquals(0.27027, stk.peek());
+
+ stk.push(-8.554);
+ Math.Parse("/", stk);
+ StackCommands.cmdRound(stk, "5");
+ assertEquals(-0.0316, stk.peek());
assertEquals(1, stk.size());
}
@@ -119,10 +137,14 @@ void testPower() {
// Add test data to stack
stk.push(1.23456);
stk.push(4.56789);
-
Math.Parse("^", stk);
StackCommands.cmdRound(stk, "5");
assertEquals(2.61829, stk.peek());
+
+ stk.push(3.0);
+ Math.Parse("^", stk);
+ StackCommands.cmdRound(stk, "5");
+ assertEquals(17.94954, stk.peek());
assertEquals(1, stk.size());
}
@@ -131,7 +153,6 @@ void testPower() {
*/
@Test
void testGreatestCommonDivisor() {
-
assertEquals(10, Math.GreatestCommonDivisor(90, 100));
assertEquals(3, Math.GreatestCommonDivisor(123, 456));
assertEquals(3, Math.GreatestCommonDivisor(123, 225));
diff --git a/src/test/java/org/fross/rpncalc/StackCommandsTest.java b/src/test/java/org/fross/rpncalc/StackCommandsTest.java
index 6a2c1bf..3bac01c 100644
--- a/src/test/java/org/fross/rpncalc/StackCommandsTest.java
+++ b/src/test/java/org/fross/rpncalc/StackCommandsTest.java
@@ -83,20 +83,29 @@ void testCmdAbsoluteValue() {
@Test
void testCmdAverage() {
StackObj stk = new StackObj();
-
+
+ // Test with Keep
+ stk.push(1.1);
+ stk.push(2.2);
+ stk.push(3.3);
+ stk.push(4.4);
+ stk.push(-5.5);
+ stk.push(-6.6);
+ stk.push(-7.7);
+ StackCommands.cmdAverage(stk, "keep");
+ assertEquals(-1.2571428571428573, stk.peek());
+ assertEquals(8, stk.size());
+
+ // Test without keep
stk.push(1.23);
stk.push(2.34);
stk.push(3.45);
stk.push(4.56);
stk.push(5.67);
-
- StackCommands.cmdAverage(stk, "keep");
- assertEquals(3.45, stk.pop());
- assertEquals(5, stk.size());
-
StackCommands.cmdAverage(stk, "");
- assertEquals(3.45, stk.peek());
+ assertEquals(0.5532967032967032, stk.peek());
assertEquals(1, stk.size());
+
}
/**
diff --git a/src/test/java/org/fross/rpncalc/StackOperationsTest.java b/src/test/java/org/fross/rpncalc/StackOperationsTest.java
index 3f8b143..2c5c631 100644
--- a/src/test/java/org/fross/rpncalc/StackOperationsTest.java
+++ b/src/test/java/org/fross/rpncalc/StackOperationsTest.java
@@ -159,5 +159,24 @@ void testLoadCommand() {
Output.printColorln(Ansi.Color.RED, e.getMessage());
}
}
+
+ @Test
+ void testStackSwap() {
+ StackObj stk1 = new StackObj();
+ StackObj stk2 = new StackObj();
+
+ // Standard numbers
+ CommandParser.Parse(stk1, stk2, "123", "123", "");
+ CommandParser.Parse(stk1, stk2, "456.789", "456.789", "");
+ assertEquals(2, stk1.size());
+
+ // Swap the stack and the size should be 0
+ CommandParser.Parse(stk1, stk2, "ss", "ss", "");
+ assertEquals(0, stk1.size());
+
+ // Swap it back and we should be at 2 again
+ CommandParser.Parse(stk1, stk2, "ss", "ss", "");
+ assertEquals(2, stk1.size());
+ }
}