Skip to content

Commit 67f0561

Browse files
committed
Added in2ft and ft2in commands
Added tests for the new converesions Updated user guide Updated shade plugin from 3.5.2 -> 3.5.3 Updated jUnit from 5.10.2 -> 5.11.0-M1 Updated jLine from 3.25.1 -> 3.26.1
1 parent 43b0b69 commit 67f0561

File tree

7 files changed

+115
-31
lines changed

7 files changed

+115
-31
lines changed

mdbook/src/Chapters/Conversions.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ The `frac [base]` command takes the item on the top of the stack (`line1`) and d
1717
if `frac 5` would have been entered (which means 1/5 is maximum granularity), you get `1.1234 is approximately 1 1/5`.
1818

1919

20-
|<div style="width:90px">Command</div>|Description|
21-
|-------|-----------|
22-
|to%|Converts `line1` from a "number" to a percent. For example, `0.4455` becomes `44.55%`. This is simply done by multiplying the number by 100|
23-
|from%|Converts `line1` from a percent to a "number". For example, `93.124%` becomes `.93124`. This is simply done by multiplying the number by 0.01|
24-
|frac [base]|Display a fractional estimate of the last stack item (`line1`) with the maximum granularity of 1/[base]. See the above description for more detail|
25-
|in2mm|Converts the value in `line1` from inches to millimeters|
26-
|mm2in|Converts the value in `line1` from millimeters to inches|
27-
|deg2rad|Convert `line1` from degrees into [radians](https://en.wikipedia.org/wiki/Radian)|
28-
|rad2deg|Convert `line1` from radians into degrees|
29-
|gram2oz<br>grams2oz|Convert `line1` from grams into ounces using the constant of 0.035274 ounces / gram|
30-
|oz2gram<br>oz2grams|Convert `line1` from ounces into grams using the constant of 28.349523125 grams / ounce|
31-
|kg2lbs<br>kgs2lbs|convert `line1` from kilograms to US pounds using the constant of 2.2046226218 lbs/kg|
32-
|lbs2kg<br>lbs2kgs|convert `line1` from US pounds using the constant of 0.45359237 kg/lbs|
20+
| <div style="width:90px">Command</div> | Description |
21+
|---------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
22+
| to% | Converts `line1` from a "number" to a percent. For example, `0.4455` becomes `44.55%`. This is simply done by multiplying the number by 100 |
23+
| from% | Converts `line1` from a percent to a "number". For example, `93.124%` becomes `.93124`. This is simply done by multiplying the number by 0.01 |
24+
| frac [base] | Display a fractional estimate of the last stack item (`line1`) with the maximum granularity of 1/[base]. See the above description for more detail |
25+
| in2mm | Converts the value in `line1` from inches to millimeters |
26+
| mm2in | Converts the value in `line1` from millimeters to inches |
27+
| in2ft | Converts the value in `line1` from inches to feet |
28+
| ft2in | Converts the value in `line1` from feet to inches |
29+
| deg2rad | Convert `line1` from degrees into [radians](https://en.wikipedia.org/wiki/Radian) |
30+
| rad2deg | Convert `line1` from radians into degrees |
31+
| gram2oz<br>grams2oz | Convert `line1` from grams into ounces using the constant of 0.035274 ounces / gram |
32+
| oz2gram<br>oz2grams | Convert `line1` from ounces into grams using the constant of 28.349523125 grams / ounce |
33+
| kg2lbs<br>kgs2lbs | convert `line1` from kilograms to US pounds using the constant of 2.2046226218 lbs/kg |
34+
| lbs2kg<br>lbs2kgs | convert `line1` from US pounds using the constant of 0.45359237 kg/lbs |

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.fross</groupId>
55
<artifactId>rpncalc</artifactId>
6-
<version>5.2.5</version>
6+
<version>5.2.6</version>
77
<packaging>jar</packaging>
88

99
<name>rpncalc</name>
@@ -113,7 +113,7 @@
113113
<plugin>
114114
<groupId>org.apache.maven.plugins</groupId>
115115
<artifactId>maven-shade-plugin</artifactId>
116-
<version>3.5.2</version>
116+
<version>3.5.3</version>
117117
<executions>
118118
<execution>
119119
<phase>package</phase>
@@ -273,23 +273,23 @@
273273
<dependency>
274274
<groupId>org.junit.jupiter</groupId>
275275
<artifactId>junit-jupiter</artifactId>
276-
<version>5.10.2</version>
276+
<version>5.11.0-M1</version>
277277
<scope>test</scope>
278278
</dependency>
279279

280280
<!-- https://mvnrepository.com/artifact/org.jline/jline-reader -->
281281
<dependency>
282282
<groupId>org.jline</groupId>
283283
<artifactId>jline-reader</artifactId>
284-
<version>3.25.1</version>
284+
<version>3.26.1</version>
285285
</dependency>
286286

287287
<!-- https://mvnrepository.com/artifact/org.jline/jline-terminal-jansi -->
288288
<!-- Needed to remove jline warning when app starts -->
289289
<dependency>
290290
<groupId>org.jline</groupId>
291291
<artifactId>jline-terminal-jansi</artifactId>
292-
<version>3.25.1</version>
292+
<version>3.26.1</version>
293293
</dependency>
294294

295295
</dependencies>

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: rpncalc
2-
version: '5.2.5'
2+
version: '5.2.6'
33
summary: The command line Reverse Polish Notation (RPN) calculator
44
description: |
55
RPNCalc is an easy to use command line based Reverse Polish

src/main/java/org/fross/rpncalc/CommandParser.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,22 @@ public static void Parse(StackObj calcStack, StackObj calcStack2, String cmdInpu
222222

223223
// Convert inches to millimeters
224224
case "in2mm":
225-
StackConversions.cmdConvertIN2MM(calcStack);
225+
StackConversions.cmdIn2Mm(calcStack);
226226
break;
227227

228228
// Convert millimeters to inches
229229
case "mm2in":
230-
StackConversions.cmdConvertMM2IN(calcStack);
230+
StackConversions.cmdMm2In(calcStack);
231+
break;
232+
233+
// Convert inches to feet
234+
case "in2ft":
235+
StackConversions.cmdIn2Ft(calcStack);
236+
break;
237+
238+
// Convert feet to inches
239+
case "ft2in":
240+
StackConversions.cmdFt2In(calcStack);
231241
break;
232242

233243
// Convert to Radians

src/main/java/org/fross/rpncalc/Help.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public static void Display() {
104104
Output.printColorln(Ansi.Color.WHITE, " rad2deg Convert line1 from radians to degrees");
105105
Output.printColorln(Ansi.Color.WHITE, " in2mm Convert line1 from inches into millimeters");
106106
Output.printColorln(Ansi.Color.WHITE, " mm2in Convert line1 from millimeters to inches");
107+
Output.printColorln(Ansi.Color.WHITE, " in2ft Convert line1 from inches into feet");
108+
Output.printColorln(Ansi.Color.WHITE, " ft2in Convert line1 from feet to inches");
107109
Output.printColorln(Ansi.Color.WHITE, " gram2oz Convert line1 from grams to US ounces");
108110
Output.printColorln(Ansi.Color.WHITE, " oz2gram Convert line1 from US ounces to grams");
109111
Output.printColorln(Ansi.Color.WHITE, " kg2lbs Convert line1 from kilograms to US pounds");

src/main/java/org/fross/rpncalc/StackConversions.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public static void cmdToPercent(StackObj calcStack) {
7575
}
7676

7777
/**
78-
* cmdConvertMM(): Assumes Line1 is in inches and converts to millimeters
78+
* cmdConvertIn2Mm(): Assumes Line1 is in inches and converts to millimeters
7979
*/
80-
public static void cmdConvertIN2MM(StackObj calcStack) {
80+
public static void cmdIn2Mm(StackObj calcStack) {
8181
// Verify at least one elements exists
8282
if (calcStack.isEmpty()) {
8383
Output.printColorln(Ansi.Color.RED, "Error: There must be at least 1 element on the stack to convert");
@@ -92,9 +92,9 @@ public static void cmdConvertIN2MM(StackObj calcStack) {
9292
}
9393

9494
/**
95-
* cmdConvertIN(): Assumes Line1 is in millimeters and converts to inches
95+
* cmdConvertMm2In(): Assumes Line1 is in millimeters and converts to inches
9696
*/
97-
public static void cmdConvertMM2IN(StackObj calcStack) {
97+
public static void cmdMm2In(StackObj calcStack) {
9898
// Verify at least one elements exists
9999
if (calcStack.isEmpty()) {
100100
Output.printColorln(Ansi.Color.RED, "Error: There must be at least 1 element on the stack to convert");
@@ -108,6 +108,40 @@ public static void cmdConvertMM2IN(StackObj calcStack) {
108108
calcStack.push(calcStack.pop().divide(new BigDecimal("25.4"), MathContext.DECIMAL128));
109109
}
110110

111+
/**
112+
* cmdConvertIn2Ft(): Assumes Line1 is in inches and converts to feet
113+
*/
114+
public static void cmdIn2Ft(StackObj calcStack) {
115+
// Verify at least one elements exists
116+
if (calcStack.isEmpty()) {
117+
Output.printColorln(Ansi.Color.RED, "Error: There must be at least 1 element on the stack to convert");
118+
return;
119+
}
120+
121+
// Save current calcStack to the undoStack
122+
calcStack.saveUndo();
123+
124+
// Pop off the last value, convert, and push it back
125+
calcStack.push(calcStack.pop().divide(new BigDecimal("12"), MathContext.DECIMAL128));
126+
}
127+
128+
/**
129+
* cmdConvertFt2In(): Assumes Line1 is in feet and converts to inches
130+
*/
131+
public static void cmdFt2In(StackObj calcStack) {
132+
// Verify at least one elements exists
133+
if (calcStack.isEmpty()) {
134+
Output.printColorln(Ansi.Color.RED, "Error: There must be at least 1 element on the stack to convert");
135+
return;
136+
}
137+
138+
// Save current calcStack to the undoStack
139+
calcStack.saveUndo();
140+
141+
// Pop off the last value, convert, and push it back
142+
calcStack.push(calcStack.pop().multiply(new BigDecimal("12")));
143+
}
144+
111145
/**
112146
* cmdFraction(): Display the last stack item as a fraction with a minimum base of the provided number. For example, sending
113147
* 64 would produce a fraction of 1/64th but will be reduced if possible.

src/test/java/org/fross/rpncalc/StackConversionsTest.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,39 +92,39 @@ void testCmdToPercent() {
9292
}
9393

9494
/**
95-
* Test method for {@link org.fross.rpncalc.StackConversions#cmdConvertIN2MM(org.fross.rpncalc.StackObj)}.
95+
* Test method for {@link org.fross.rpncalc.StackConversions#cmdIn2Mm(org.fross.rpncalc.StackObj)}.
9696
*/
9797
@Test
9898
void testCmdConvertIN2MM() {
9999
StackObj stk = new StackObj();
100100

101101
stk.push(31.6);
102-
StackConversions.cmdConvertIN2MM(stk);
102+
StackConversions.cmdIn2Mm(stk);
103103
assertEquals(802.64, stk.peek().doubleValue());
104104
assertEquals(1, stk.size());
105105

106106
stk.push(1.234e12);
107-
StackConversions.cmdConvertIN2MM(stk);
107+
StackConversions.cmdIn2Mm(stk);
108108
assertEquals("3.13436E+13", stk.peek().toString());
109109
assertEquals(2, stk.size());
110110

111111
}
112112

113113
/**
114-
* Test method for {@link org.fross.rpncalc.StackConversions#cmdConvertMM2IN(org.fross.rpncalc.StackObj)}.
114+
* Test method for {@link org.fross.rpncalc.StackConversions#cmdMm2In(org.fross.rpncalc.StackObj)}.
115115
*/
116116
@Test
117117
void testCmdConvertMM2IN() {
118118
StackObj stk = new StackObj();
119119

120120
stk.push(666.0);
121-
StackConversions.cmdConvertMM2IN(stk);
121+
StackConversions.cmdMm2In(stk);
122122
StackCommands.cmdRound(stk, "4");
123123
assertEquals(26.2205, stk.peek().doubleValue());
124124
assertEquals(1, stk.size());
125125

126126
stk.push(1.234e12);
127-
StackConversions.cmdConvertMM2IN(stk);
127+
StackConversions.cmdMm2In(stk);
128128
StackCommands.cmdRound(stk, "10");
129129
assertEquals("48582677165.3543307087", stk.peek().toEngineeringString());
130130
assertEquals(2, stk.size());
@@ -498,4 +498,40 @@ void testLbs2Kg() {
498498
assertEquals("1959972630770000000.00", stk.pop().toEngineeringString());
499499
}
500500

501+
/**
502+
* Test Inches to Feet conversion
503+
*/
504+
@Test
505+
void testIn2Ft() {
506+
StackObj stk = new StackObj();
507+
508+
stk.push(123.321);
509+
StackConversions.cmdIn2Ft(stk);
510+
StackCommands.cmdRound(stk, "5");
511+
assertEquals(10.27675, stk.pop().doubleValue());
512+
513+
stk.push(-50.987654);
514+
StackConversions.cmdIn2Ft(stk);
515+
StackCommands.cmdRound(stk, "5");
516+
assertEquals(-4.24897, stk.pop().doubleValue());
517+
}
518+
519+
/**
520+
* Test Feet to Inches conversion
521+
*/
522+
@Test
523+
void testFt2In() {
524+
StackObj stk = new StackObj();
525+
526+
stk.push(7117.44);
527+
StackConversions.cmdFt2In(stk);
528+
StackCommands.cmdRound(stk, "5");
529+
assertEquals(85409.28, stk.pop().doubleValue());
530+
531+
stk.push(-32.0011);
532+
StackConversions.cmdFt2In(stk);
533+
StackCommands.cmdRound(stk, "5");
534+
assertEquals(-384.0132, stk.pop().doubleValue());
535+
}
536+
501537
}

0 commit comments

Comments
 (0)