Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support percentage by parsing percentage to double (#906)
* support percentage by parsing percentage to double and add corresponding tests * support percentage by parsing percentage to double and add corresponding tests(update) * simpify code * Solve conflict
- Loading branch information
1 parent
16147ed
commit 04e6d6b
Showing
4 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/test/java/tech/tablesaw/api/DoubleParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package tech.tablesaw.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import tech.tablesaw.columns.numbers.DoubleParser; | ||
|
||
class DoubleParserTest { | ||
@Test | ||
void testCanParse1() { | ||
DoubleParser doubleParser = new DoubleParser(ColumnType.DOUBLE); | ||
assertTrue(doubleParser.canParse("1.3")); | ||
} | ||
|
||
@Test | ||
void testCanParse2() { | ||
DoubleParser doubleParser = new DoubleParser(ColumnType.DOUBLE); | ||
assertTrue(doubleParser.canParse("1.3%")); | ||
} | ||
|
||
@Test | ||
void testCanParse3() { | ||
DoubleParser doubleParser = new DoubleParser(ColumnType.DOUBLE); | ||
assertFalse(doubleParser.canParse("%")); | ||
} | ||
|
||
@Test | ||
void testParseDouble1() { | ||
DoubleParser doubleParser = new DoubleParser(ColumnType.DOUBLE); | ||
assertEquals(1.3, doubleParser.parseDouble("1.3")); | ||
} | ||
|
||
@Test | ||
void testParseDouble2() { | ||
DoubleParser doubleParser = new DoubleParser(ColumnType.DOUBLE); | ||
assertEquals(0.012, doubleParser.parseDouble("1.2%")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Currency,Percentage,double | ||
$10.3,1.32%,13.14 | ||
$50.10,32.768%,35 | ||
$10,100%,93.131 |