void DrawingManager::mouseDown(double x, double y){ if (mode == DRAW_M); //addPoint(x,y); else if (mode == SELECT_M || mode == SCALE_M) checkSelect(x,y); else if (mode == DIRECT_M) checkDSelect(x,y); else if (mode == ELLIPSE_M || mode== LINE_M || mode==RECT_M) startShape(x,y); if (mode== PARENT_M) parent(x,y); }
void PluralRulesTest::testSelect() { UErrorCode status = U_ZERO_ERROR; LocalPointer<PluralRules> pr(PluralRules::createRules("s: n in 1,3,4,6", status)); checkSelect(pr, status, __LINE__, "s", "1.0", "3.0", "4.0", "6.0", END_MARK); checkSelect(pr, status, __LINE__, "other", "0.0", "2.0", "3.1", "7.0", END_MARK); pr.adoptInstead(PluralRules::createRules("s: n not in 1,3,4,6", status)); checkSelect(pr, status, __LINE__, "other", "1.0", "3.0", "4.0", "6.0", END_MARK); checkSelect(pr, status, __LINE__, "s", "0.0", "2.0", "3.1", "7.0", END_MARK); pr.adoptInstead(PluralRules::createRules("r: n in 1..4, 7..10, 14 .. 17;" "s: n is 29;", status)); checkSelect(pr, status, __LINE__, "r", "1.0", "3.0", "7.0", "8.0", "10.0", "14.0", "17.0", END_MARK); checkSelect(pr, status, __LINE__, "s", "29.0", END_MARK); checkSelect(pr, status, __LINE__, "other", "28.0", "29.1", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 is 1; b: n mod 100 is 0 ", status)); checkSelect(pr, status, __LINE__, "a", "1", "11", "41", "101", "301.00", END_MARK); checkSelect(pr, status, __LINE__, "b", "0", "100", "200.0", "300.", "1000", "1100", "110000", END_MARK); checkSelect(pr, status, __LINE__, "other", "0.01", "1.01", "0.99", "2", "3", "99", "102", END_MARK); // Rules that end with or without a ';' and with or without trailing spaces. // (There was a rule parser bug here with these.) pr.adoptInstead(PluralRules::createRules("a: n is 1", status)); checkSelect(pr, status, __LINE__, "a", "1", END_MARK); checkSelect(pr, status, __LINE__, "other", "2", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n is 1 ", status)); checkSelect(pr, status, __LINE__, "a", "1", END_MARK); checkSelect(pr, status, __LINE__, "other", "2", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n is 1;", status)); checkSelect(pr, status, __LINE__, "a", "1", END_MARK); checkSelect(pr, status, __LINE__, "other", "2", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n is 1 ; ", status)); checkSelect(pr, status, __LINE__, "a", "1", END_MARK); checkSelect(pr, status, __LINE__, "other", "2", END_MARK); // First match when rules for different keywords are not disjoint. // Also try spacing variations around ':' and '..' pr.adoptInstead(PluralRules::createRules("c: n in 5..15; b : n in 1..10 ;a:n in 10 .. 20", status)); checkSelect(pr, status, __LINE__, "a", "20", END_MARK); checkSelect(pr, status, __LINE__, "b", "1", END_MARK); checkSelect(pr, status, __LINE__, "c", "10", END_MARK); checkSelect(pr, status, __LINE__, "other", "0", "21", "10.1", END_MARK); // in vs within pr.adoptInstead(PluralRules::createRules("a: n in 2..10; b: n within 8..15", status)); checkSelect(pr, status, __LINE__, "a", "2", "8", "10", END_MARK); checkSelect(pr, status, __LINE__, "b", "8.01", "9.5", "11", "14.99", "15", END_MARK); checkSelect(pr, status, __LINE__, "other", "1", "7.7", "15.01", "16", END_MARK); // OR and AND chains. pr.adoptInstead(PluralRules::createRules("a: n in 2..10 and n in 4..12 and n not in 5..7", status)); checkSelect(pr, status, __LINE__, "a", "4", "8", "9", "10", END_MARK); checkSelect(pr, status, __LINE__, "other", "2", "3", "5", "7", "11", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n is 2 or n is 5 or n in 7..11 and n in 11..13", status)); checkSelect(pr, status, __LINE__, "a", "2", "5", "11", END_MARK); checkSelect(pr, status, __LINE__, "other", "3", "4", "6", "8", "10", "12", "13", END_MARK); // Number attributes - // n: the number itself // i: integer digits // f: visible fraction digits // t: f with trailing zeros removed. // v: number of visible fraction digits // j: = n if there are no visible fraction digits // != anything if there are visible fraction digits pr.adoptInstead(PluralRules::createRules("a: i is 123", status)); checkSelect(pr, status, __LINE__, "a", "123", "123.0", "123.1", "0123.99", END_MARK); checkSelect(pr, status, __LINE__, "other", "124", "122.0", END_MARK); pr.adoptInstead(PluralRules::createRules("a: f is 120", status)); checkSelect(pr, status, __LINE__, "a", "1.120", "0.120", "11123.120", "0123.120", END_MARK); checkSelect(pr, status, __LINE__, "other", "1.121", "122.1200", "1.12", "120", END_MARK); pr.adoptInstead(PluralRules::createRules("a: t is 12", status)); checkSelect(pr, status, __LINE__, "a", "1.120", "0.12", "11123.12000", "0123.1200000", END_MARK); checkSelect(pr, status, __LINE__, "other", "1.121", "122.1200001", "1.11", "12", END_MARK); pr.adoptInstead(PluralRules::createRules("a: v is 3", status)); checkSelect(pr, status, __LINE__, "a", "1.120", "0.000", "11123.100", "0123.124", ".666", END_MARK); checkSelect(pr, status, __LINE__, "other", "1.1212", "122.12", "1.1", "122", "0.0000", END_MARK); pr.adoptInstead(PluralRules::createRules("a: v is 0 and i is 123", status)); checkSelect(pr, status, __LINE__, "a", "123", "123.", END_MARK); checkSelect(pr, status, __LINE__, "other", "123.0", "123.1", "123.123", "0.123", END_MARK); // The reserved words from the rule syntax will also function as keywords. pr.adoptInstead(PluralRules::createRules("a: n is 21; n: n is 22; i: n is 23; f: n is 24;" "t: n is 25; v: n is 26; w: n is 27; j: n is 28" , status)); checkSelect(pr, status, __LINE__, "other", "20", "29", END_MARK); checkSelect(pr, status, __LINE__, "a", "21", END_MARK); checkSelect(pr, status, __LINE__, "n", "22", END_MARK); checkSelect(pr, status, __LINE__, "i", "23", END_MARK); checkSelect(pr, status, __LINE__, "f", "24", END_MARK); checkSelect(pr, status, __LINE__, "t", "25", END_MARK); checkSelect(pr, status, __LINE__, "v", "26", END_MARK); checkSelect(pr, status, __LINE__, "w", "27", END_MARK); checkSelect(pr, status, __LINE__, "j", "28", END_MARK); pr.adoptInstead(PluralRules::createRules("not: n=31; and: n=32; or: n=33; mod: n=34;" "in: n=35; within: n=36;is:n=37" , status)); checkSelect(pr, status, __LINE__, "other", "30", "39", END_MARK); checkSelect(pr, status, __LINE__, "not", "31", END_MARK); checkSelect(pr, status, __LINE__, "and", "32", END_MARK); checkSelect(pr, status, __LINE__, "or", "33", END_MARK); checkSelect(pr, status, __LINE__, "mod", "34", END_MARK); checkSelect(pr, status, __LINE__, "in", "35", END_MARK); checkSelect(pr, status, __LINE__, "within", "36", END_MARK); checkSelect(pr, status, __LINE__, "is", "37", END_MARK); // Test cases from ICU4J PluralRulesTest.parseTestData pr.adoptInstead(PluralRules::createRules("a: n is 1", status)); checkSelect(pr, status, __LINE__, "a", "1", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 is 2", status)); checkSelect(pr, status, __LINE__, "a", "2", "12", "22", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n is not 1", status)); checkSelect(pr, status, __LINE__, "a", "0", "2", "3", "4", "5", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 3 is not 1", status)); checkSelect(pr, status, __LINE__, "a", "0", "2", "3", "5", "6", "8", "9", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n in 2..5", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "4", "5", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n within 2..5", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "4", "5", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n not in 2..5", status)); checkSelect(pr, status, __LINE__, "a", "0", "1", "6", "7", "8", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n not within 2..5", status)); checkSelect(pr, status, __LINE__, "a", "0", "1", "6", "7", "8", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 in 2..5", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "4", "5", "12", "13", "14", "15", "22", "23", "24", "25", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 within 2..5", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "4", "5", "12", "13", "14", "15", "22", "23", "24", "25", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 is 2 and n is not 12", status)); checkSelect(pr, status, __LINE__, "a", "2", "22", "32", "42", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 in 2..3 or n mod 10 is 5", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "5", "12", "13", "15", "22", "23", "25", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 within 2..3 or n mod 10 is 5", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "5", "12", "13", "15", "22", "23", "25", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n is 1 or n is 4 or n is 23", status)); checkSelect(pr, status, __LINE__, "a", "1", "4", "23", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 2 is 1 and n is not 3 and n in 1..11", status)); checkSelect(pr, status, __LINE__, "a", "1", "5", "7", "9", "11", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 2 is 1 and n is not 3 and n within 1..11", status)); checkSelect(pr, status, __LINE__, "a", "1", "5", "7", "9", "11", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 2 is 1 or n mod 5 is 1 and n is not 6", status)); checkSelect(pr, status, __LINE__, "a", "1", "3", "5", "7", "9", "11", "13", "15", "16", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n in 2..5; b: n in 5..8; c: n mod 2 is 1", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "4", "5", END_MARK); checkSelect(pr, status, __LINE__, "b", "6", "7", "8", END_MARK); checkSelect(pr, status, __LINE__, "c", "1", "9", "11", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n within 2..5; b: n within 5..8; c: n mod 2 is 1", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "4", "5", END_MARK); checkSelect(pr, status, __LINE__, "b", "6", "7", "8", END_MARK); checkSelect(pr, status, __LINE__, "c", "1", "9", "11", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n in 2, 4..6; b: n within 7..9,11..12,20", status)); checkSelect(pr, status, __LINE__, "a", "2", "4", "5", "6", END_MARK); checkSelect(pr, status, __LINE__, "b", "7", "8", "9", "11", "12", "20", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n in 2..8, 12 and n not in 4..6", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "7", "8", "12", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n mod 10 in 2, 3,5..7 and n is not 12", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "5", "6", "7", "13", "15", "16", "17", END_MARK); pr.adoptInstead(PluralRules::createRules("a: n in 2..6, 3..7", status)); checkSelect(pr, status, __LINE__, "a", "2", "3", "4", "5", "6", "7", END_MARK); // Extended Syntax, with '=', '!=' and '%' operators. pr.adoptInstead(PluralRules::createRules("a: n = 1..8 and n!= 2,3,4,5", status)); checkSelect(pr, status, __LINE__, "a", "1", "6", "7", "8", END_MARK); checkSelect(pr, status, __LINE__, "other", "0", "2", "3", "4", "5", "9", END_MARK); pr.adoptInstead(PluralRules::createRules("a:n % 10 != 1", status)); checkSelect(pr, status, __LINE__, "a", "2", "6", "7", "8", END_MARK); checkSelect(pr, status, __LINE__, "other", "1", "21", "211", "91", END_MARK); }