diff --git a/Swifternalization/SharedRussianExpression.swift b/Swifternalization/SharedRussianExpression.swift index 04d1524..7efdbd3 100644 --- a/Swifternalization/SharedRussianExpression.swift +++ b/Swifternalization/SharedRussianExpression.swift @@ -19,28 +19,41 @@ class SharedRussianExpression: SharedExpressionProtocol { /** 1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, … + v = 0 and + i % 10 = 1 and + i % 100 != 11 + e.g. - из 1 книги за 1 день */ SharedExpression(identifier: "one", pattern: "exp:(^1$)|(^[^1]1$)|(^[1-9][0-9]?[0,2,3,4,5,6,7,8,9]+1$)"), /** - (2-4), (22-24), (32-4), ..., (..>22, ..>23, ..>24) + 2~4, 22~24, 32~34, 42~44, 52~54, 62, 102, 1002, … + + v = 0 and + i % 10 = 2..4 and + i % 100 != 12..14 e.g. - - 22 samochody, 1334 samochody, 53 samochody - - 2 minuty, 4 minuty, 23 minuty + - из 2 книг за 2 дня */ SharedExpression(identifier: "few", pattern: "exp:(((?!1).[2-4]{1})$)|(^[2-4]$)"), /** - 0, (5-9), (10-21), (25-31), ..., (..0, ..1, ..5-9) + 0, 5~20, 100, 1000, 10000, 100000, 1000000, … + + v = 0 and + i % 10 = 0 or + v = 0 and + i % 10 = 5..9 or + v = 0 and + i % 100 = 11..14 e.g. - - 0 samochodów, 10 samochodów, 26 samochodów, 1147 samochodów - - 5 minut, 18 minut, 117 minut, 1009 minut + - из 5 книг за 5 дней */ - SharedExpression(identifier: "many", pattern: "exp:(^[05-9]$)|(.*(?=1).[0-9]$)|(^[0-9]{1}.*[0156789]$)"), + SharedExpression(identifier: "many", pattern: "exp:(^[05-9]$)|(^1[1-4]$)|(^[1-9]+[0-9]*[5-9]$)|(^[1-9]+[0-9]*1{1}[1-4]$)|([1-9]+[0-9]*0$)"), ] } } diff --git a/SwifternalizationTests/SharedRussianExpressionTests.swift b/SwifternalizationTests/SharedRussianExpressionTests.swift index 673f228..c80a949 100644 --- a/SwifternalizationTests/SharedRussianExpressionTests.swift +++ b/SwifternalizationTests/SharedRussianExpressionTests.swift @@ -28,13 +28,34 @@ class SharedRussianExpressionTests: XCTestCase { XCTAssertFalse(expression.validate("1211"), "Should not match 1211") } + func testFew() { + let sharedExp = SharedRussianExpression.allExpressions().filter({$0.identifier == "few"}).first! + let expression = Expression(pattern: sharedExp.pattern, value: "") + + XCTAssertTrue(expression.validate("2"), "Should match 2") + XCTAssertTrue(expression.validate("23"), "Should match 23") + XCTAssertTrue(expression.validate("564"), "Should match 564") + XCTAssertTrue(expression.validate("1873"), "Should match 1873") + + XCTAssertFalse(expression.validate("5"), "Should not match 5") + XCTAssertFalse(expression.validate("12"), "Should not match 12") + XCTAssertFalse(expression.validate("18"), "Should not match 18") + XCTAssertFalse(expression.validate("39"), "Should not match 39") + XCTAssertFalse(expression.validate("1413"), "Should not match 1413") + XCTAssertFalse(expression.validate("41511"), "Should not match 41511") + } + func testMany() { - let sharedExp = SharedPolishExpression.allExpressions().filter({$0.identifier == "many"}).first! + let sharedExp = SharedRussianExpression.allExpressions().filter({$0.identifier == "many"}).first! let expression = Expression(pattern: sharedExp.pattern, value: "") + XCTAssertTrue(expression.validate("0"), "Should match 0") + XCTAssertTrue(expression.validate("6"), "Should match 6") XCTAssertTrue(expression.validate("10"), "Should match 10") XCTAssertTrue(expression.validate("18"), "Should match 18") XCTAssertTrue(expression.validate("1009"), "Should match 1009") + XCTAssertTrue(expression.validate("2011"), "Should match 2011") + XCTAssertTrue(expression.validate("8314"), "Should match 8314") XCTAssertFalse(expression.validate("22"), "Should not match 22") XCTAssertFalse(expression.validate("24"), "Should not match 24")