mirror of
https://github.com/Kindelia/Kind2.git
synced 2024-10-26 08:09:22 +03:00
Update TestSuite, add more functions to String
This commit is contained in:
parent
6dd13207d2
commit
24da3ab5a5
2
base/Char/is_digit.kind
Normal file
2
base/Char/is_digit.kind
Normal file
@ -0,0 +1,2 @@
|
||||
Char.is_digit(c: Char): Bool
|
||||
Bool.and(U16.gte(c,'0'),U16.lte(c,'9'))
|
10
base/String/is_nat.kind
Normal file
10
base/String/is_nat.kind
Normal file
@ -0,0 +1,10 @@
|
||||
String.is_nat(s: String): Bool
|
||||
String.is_nat.aux(s, true)
|
||||
|
||||
String.is_nat.aux(s: String, aux: Bool): Bool
|
||||
case s {
|
||||
nil : aux
|
||||
cons:
|
||||
let is_digit = Bool.and(Char.is_digit(s.head),aux)
|
||||
String.is_nat.aux(s.tail, is_digit)
|
||||
}
|
@ -1,4 +1,11 @@
|
||||
String.test.all: TestSuite
|
||||
TestSuite.many("String", [
|
||||
String.test.to_hex
|
||||
])
|
||||
TestSuite.many("String",
|
||||
[
|
||||
String.test.to_hex,
|
||||
String.test.is_nat
|
||||
])
|
||||
|
||||
// Show all tests for String
|
||||
String.test.show: _
|
||||
log(TestSuite.show(String.test.all, 0))
|
||||
0
|
||||
|
47
base/String/test/is_nat.kind
Normal file
47
base/String/test/is_nat.kind
Normal file
@ -0,0 +1,47 @@
|
||||
String.test.is_nat: TestSuite
|
||||
TestSuite.many("String.is_number", [
|
||||
String.test.is_nat.0, String.test.is_nat.1, String.test.is_nat.2,
|
||||
String.test.is_nat.3, String.test.is_nat.4, String.test.is_nat.5,
|
||||
])
|
||||
|
||||
String.test.is_nat.0: TestSuite
|
||||
let test = "0123"
|
||||
let got = Bool.show(String.is_nat(test))
|
||||
let exp = "Bool.true"
|
||||
let name = "0"
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.is_nat.1: TestSuite
|
||||
let test = "-987"
|
||||
let got = Bool.show(String.is_nat(test))
|
||||
let exp = "Bool.false"
|
||||
let name = "1"
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.is_nat.2: TestSuite
|
||||
let test = "0865a"
|
||||
let got = Bool.show(String.is_nat(test))
|
||||
let exp = "Bool.false"
|
||||
let name = "2"
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.is_nat.3: TestSuite
|
||||
let test = "9007199254740991n"
|
||||
let got = Bool.show(String.is_nat(test))
|
||||
let exp = "Bool.false"
|
||||
let name = "3"
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.is_nat.4: TestSuite
|
||||
let test = "011101011101"
|
||||
let got = Bool.show(String.is_nat(test))
|
||||
let exp = "Bool.true"
|
||||
let name = "4"
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.is_nat.5: TestSuite
|
||||
let test = "2.3847623487236483e+24"
|
||||
let got = Bool.show(String.is_nat(test))
|
||||
let exp = "Bool.false"
|
||||
let name = "5"
|
||||
TestSuite.show.string(name, test, exp, got)
|
@ -13,73 +13,73 @@ String.test.to_hex: TestSuite
|
||||
|
||||
String.test.to_hex.0: TestSuite
|
||||
let test = "abcdef"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "616263646566"
|
||||
let name = "0"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.to_hex.1: TestSuite
|
||||
let test = ""
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = ""
|
||||
let name = "1"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.to_hex.2: TestSuite
|
||||
let test = "á"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "c3a1"
|
||||
let name = "2"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.to_hex.3: TestSuite
|
||||
let test = "ü"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "c3bc"
|
||||
let name = "3"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.to_hex.4: TestSuite
|
||||
let test = "õ"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "c3b5"
|
||||
let name = "4"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.to_hex.5: TestSuite
|
||||
let test = "1234567890"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "31323334353637383930"
|
||||
let name = "5"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
String.test.to_hex.6: TestSuite
|
||||
let test = "{%$@"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "7b252440"
|
||||
let name = "6"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
// 2 bytes UTF-8
|
||||
String.test.to_hex.7: TestSuite
|
||||
let test = "¢"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "c2a2"
|
||||
let name = "7"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
// 3 bytes UTF-8
|
||||
String.test.to_hex.8: TestSuite
|
||||
let test = "ह€"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "e0a4b9e282ac"
|
||||
let name = "8"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
||||
// 4 bytes UTF-8
|
||||
String.test.to_hex.9: TestSuite
|
||||
let test = "𐍈"
|
||||
let hex = String.to_hex(test)
|
||||
let got = String.to_hex(test)
|
||||
let exp = "f0908d88"
|
||||
let name = "9"
|
||||
TestSuite.log.string(name, test, exp, hex)
|
||||
TestSuite.show.string(name, test, exp, got)
|
||||
|
@ -35,7 +35,7 @@ TestSuite.show.check_fail(s: TestSuite): String
|
||||
TestSuite.log(name: String, test: String, expected: String, got: String): String
|
||||
"\n["|name|"] test: "|test|"\nexpected: "|expected|"\ngot: "|got
|
||||
|
||||
TestSuite.log.string(name: String, test: String, expected: String, got: String): TestSuite
|
||||
TestSuite.show.string(name: String, test: String, expected: String, got: String): TestSuite
|
||||
let res =
|
||||
if String.eql(expected, got)
|
||||
then Maybe.none!
|
||||
|
Loading…
Reference in New Issue
Block a user