Advertisement
agmike

Soup Mutability

Aug 14th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. Output:
  2. * Soup Mutability: PASS (0 errors, 8 warnings)
  3. * * tag name is immutable
  4. * * tag value is immutable
  5. * * sub soup is mutable
  6. * * sub soup is mutable by old reference
  7. * * sub soup is mutable by new reference
  8. * * old reference is mutable by new reference
  9. * * new reference is mutable by old reference
  10. * * references are not equal
  11.  
  12. class Test_LData_SoupMutability isclass LTest
  13. {
  14.     string IsMutable(string subj, string comment, bool mutable)
  15.     {
  16.         if (mutable)
  17.             return subj + " is mutable " + comment;
  18.         return subj + " is immutable " + comment;
  19.     }
  20.    
  21.     public void Run(LTestContext test)
  22.     {
  23.         Soup sp = Constructors.NewSoup();
  24.         string tagName = "tagName";
  25.         string tagValue = "tagValue";
  26.         sp.SetNamedTag(tagName, tagValue);
  27.         tagName[0] = 'T';
  28.         tagValue[0] = 'T';
  29.         test.Warn(IsMutable("tag name", "", LData.TryGetString(sp, "TagName")));
  30.         test.Warn(IsMutable("tag value", "", LData.LastString() == "TagValue"));
  31.            
  32.         Soup subSoup = sp.GetNamedSoupAdd("soup");
  33.         subSoup.SetNamedTag("1", 1);
  34.         test.Warn(IsMutable("sub soup", "", sp.GetNamedSoup("soup").GetNamedTagAsInt("1", 0) == 1));
  35.        
  36.         Soup subSoup2 = sp.GetNamedSoup("soup");
  37.         subSoup.SetNamedTag("2", 1);
  38.         subSoup2.SetNamedTag("3", 1);
  39.         test.Warn(IsMutable("sub soup", "by old reference", sp.GetNamedSoup("soup").GetNamedTagAsInt("2", 1) == 1));
  40.         test.Warn(IsMutable("sub soup", "by new reference", sp.GetNamedSoup("soup").GetNamedTagAsInt("3", 1) == 1));
  41.         test.Warn(IsMutable("old reference", "by new reference", subSoup.GetNamedTagAsInt("3", 1) == 1));
  42.         test.Warn(IsMutable("new reference", "by old reference", subSoup2.GetNamedTagAsInt("2", 1) == 1));
  43.         if (subSoup == subSoup2)
  44.             test.Warn("references are equal");
  45.         else
  46.             test.Warn("references are not equal");
  47.     }
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement