AmountPatternTest.kt (1880B)
1 // This file is part of taler-cashless2ecash. 2 // Copyright (C) 2024 Joel Häberli 3 // 4 // taler-cashless2ecash is free software: you can redistribute it and/or modify it 5 // under the terms of the GNU Affero General Public License as published 6 // by the Free Software Foundation, either version 3 of the License, 7 // or (at your option) any later version. 8 // 9 // taler-cashless2ecash is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // 17 // SPDX-License-Identifier: AGPL3.0-or-later 18 19 package ch.bfh.habej2.wallee_c2ec 20 21 import org.junit.Test 22 23 import org.junit.Assert.* 24 25 class AmountPatternTest { 26 27 private val regex = Regex( "\\d+(\\.\\d+)?") 28 29 @Test 30 fun valid_amount_pattern_test() { 31 32 val validPatterns = listOf( 33 "0.5", 34 "0.05", 35 "1.34533434", 36 "45243.3254245235235335", 37 "1000", 38 "9383" 39 ) 40 41 validPatterns.map { 42 assertTrue(regex.matches(it)) 43 } 44 } 45 46 @Test 47 fun invalid_amount_pattern_test() { 48 49 val invalidPattern = listOf( 50 "100.", 51 "12344.234523.34", 52 ".12344.234523", 53 ".", 54 ".932487", 55 "8989.2223..", 56 "2323..342" 57 ) 58 59 invalidPattern.map { 60 assertFalse(regex.matches(it)) 61 } 62 } 63 64 @Test 65 fun how_does_split_work() { 66 67 val str = "1." 68 val first = str.split(".")[0] 69 val second = str.split(".")[1] 70 71 assertEquals("1", first) 72 assertEquals("", second) 73 } 74 }