12345678910111213141516171819202122232425262728293031323334353637383940 |
- using Invercargill;
- using Invercargill.Convert;
- void dictionary_tests() {
- Test.add_func("/invercargill/dictionary/string", () => {
- var names = new string[] {"Billy Barrow", "William Robert", "Johnny Gala", "John Doe"};
- var dict = ate(names).to_dictionary<string>(n => n.split(" ")[0]);
- dict["James"] = "James Smith";
- var billy = dict.get_or_default("Billy");
- var john = dict.get_or_default("John");
- var james = dict.get_or_default("James");
- var bob = dict.get_or_default("Bob");
- assert_cmpstr("Billy Barrow", CompareOperator.EQ, billy);
- assert_cmpstr("John Doe", CompareOperator.EQ, john);
- assert_cmpstr("James Smith", CompareOperator.EQ, james);
- assert_null(bob);
- });
- Test.add_func("/invercargill/dictionary/int", () => {
- var dict = new Dictionary<int, string>();
- dict[1999] = "Billy";
- dict[1962] = "John";
- dict[2002] = "James";
- var billy = dict.get_or_default(1999);
- var john = dict.get_or_default(1962);
- var james = dict.get_or_default(2002);
- var bob = dict.get_or_default(1840);
- assert_cmpstr("Billy", CompareOperator.EQ, billy);
- assert_cmpstr("John", CompareOperator.EQ, john);
- assert_cmpstr("James", CompareOperator.EQ, james);
- assert_null(bob);
- });
- }
|