|
| 1 | +/* |
| 2 | + * Copyright 2018 The kSAR Project. All rights reserved. |
| 3 | + * See the LICENSE file in the project root for more information. |
| 4 | + */ |
| 5 | +package net.atomique.ksar.graph |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Assertions |
| 8 | +import org.junit.jupiter.api.Assertions.assertAll |
| 9 | +import org.junit.jupiter.api.Assertions.assertEquals |
| 10 | +import org.junit.jupiter.params.ParameterizedTest |
| 11 | +import org.junit.jupiter.params.provider.Arguments |
| 12 | +import org.junit.jupiter.params.provider.Arguments.arguments |
| 13 | +import org.junit.jupiter.params.provider.MethodSource |
| 14 | +import java.text.DecimalFormat |
| 15 | +import java.util.stream.Stream |
| 16 | + |
| 17 | +class IEEE1541NumberTest { |
| 18 | + @ParameterizedTest |
| 19 | + @MethodSource("testValues") |
| 20 | + fun testFormat(testNumber: Double, expectedFactor1: String, expectedFactor1024: String) { |
| 21 | + assertAll( |
| 22 | + { |
| 23 | + assertEquals( |
| 24 | + expectedFactor1, |
| 25 | + IEEE1541Number(1).format(testNumber) |
| 26 | + ) { "factor=1; input number: $testNumber" } |
| 27 | + }, |
| 28 | + { |
| 29 | + assertEquals( |
| 30 | + expectedFactor1024, |
| 31 | + IEEE1541Number(1024).format(testNumber) |
| 32 | + ) { "factor=1024; input number: $testNumber" } |
| 33 | + } |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + companion object { |
| 38 | + @JvmStatic |
| 39 | + fun testValues(): Stream<Arguments> { |
| 40 | + val fmt = DecimalFormat("#,##0.0") |
| 41 | + return Stream.of( |
| 42 | + arguments(791.5, fmt.format(791.5), fmt.format(791.5) + " Ki"), |
| 43 | + arguments(9462.04, fmt.format(9.2) + " Ki", fmt.format(9.2) + " Mi"), |
| 44 | + arguments(25414.88, fmt.format(24.8) + " Ki", fmt.format(24.8) + " Mi"), |
| 45 | + arguments(725414.88, fmt.format(708.4) + " Ki", fmt.format(708.4) + " Mi"), |
| 46 | + arguments(2725414.88, fmt.format(2.6) + " Mi", fmt.format(2.6) + " Gi"), |
| 47 | + arguments(27254140.88, fmt.format(26.0) + " Mi", fmt.format(26.0) + " Gi"), |
| 48 | + arguments(272541400.88, fmt.format(259.9) + " Mi", fmt.format(259.9) + " Gi"), |
| 49 | + arguments(2725414000.88, fmt.format(2.5) + " Gi", fmt.format(2599.2) + " Gi"), |
| 50 | + arguments(27254140000.88, fmt.format(25.4) + " Gi", fmt.format(25991.6) + " Gi"), |
| 51 | + arguments(272541400000.88, fmt.format(253.8) + " Gi", fmt.format(259915.7) + " Gi") |
| 52 | + ) |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments