示例#1
0
 public bool AreWordsValidCommodities(string[] words)
 {
     foreach (string word in words)
     {
         if (!commodityIndex.Exists(word))
         {
             return(false);
         }
     }
     return(true);
 }
        public void UnitExpressionTest()
        {
            AliasMapper    aliasMap       = new AliasMapper();
            RomanConverter converter      = new RomanConverter();
            CommodityIndex commodityIndex = new CommodityIndex();

            aliasMap.AddAlias("glob", "C");
            aliasMap.AddAlias("pish", "X");
            ExpressionValidationHelper helper     = new ExpressionValidationHelper(aliasMap, commodityIndex);
            UnitExpression             expression = new UnitExpression(commodityIndex, aliasMap, converter, helper);

            expression.Execute("pish glob Iron is 7020 Credits");
            Assert.IsTrue(commodityIndex.Exists("Iron"));
            Assert.AreEqual <double>(commodityIndex.GetPriceByCommodity("Iron"), 78);
            expression.Execute("pish glob Iron is 6300 Credits");
            Assert.AreEqual <double>(commodityIndex.GetPriceByCommodity("Iron"), 70);
        }
        public void UnitExpressionTest()
        {
            AliasMapper    aliasMap       = new AliasMapper();
            RomanConverter converter      = new RomanConverter();
            CommodityIndex commodityIndex = new CommodityIndex();

            aliasMap.AddAlias("glob", "I");
            aliasMap.AddAlias("prok", "V");
            aliasMap.AddAlias("pish", "X");
            aliasMap.AddAlias("tegj", "L");

            ExpressionValidationHelper helper     = new ExpressionValidationHelper(aliasMap, commodityIndex);
            UnitExpression             expression = new UnitExpression(commodityIndex, aliasMap, converter, helper);

            expression.Execute("glob glob silver is 34 Credits");
            Assert.True(commodityIndex.Exists("silver"));
            Assert.Equal <double>(17, commodityIndex.GetPriceByCommodity("silver"));
            expression.Execute("glob prok iron is 400 Credits");
            Assert.Equal <double>(100, commodityIndex.GetPriceByCommodity("iron"));
        }