Example #1
0
        public void TestConstructorWithZeroNumberOfCardsAndNullTopCard()
        {
            // ARRANGE
            IAxiom    axiom         = new Axiom();
            const int numberOfCards = 0;
            ICard     topCard       = new Card(Colour.Blue, Number.Five, axiom);

            // ACT
            ArgumentException argumentException = null;
            IRuleScore        ruleScore         = null;

            try
            {
                ruleScore = new RuleScore(
                    numberOfCards: numberOfCards,
                    topCard: topCard);
            }
            catch (ArgumentException ex)
            {
                argumentException = ex;
            }

            // ASSERT
            if (argumentException != null)
            {
                Console.WriteLine(argumentException.ToString());
            }

            Assert.IsNotNull(argumentException, "argumentException != null");
            Assert.IsNull(ruleScore, "ruleScore == null");
        }
Example #2
0
        public void TestConstructorWithBadNumberOfCards(int numberOfCards)
        {
            // ARRANGE
            IAxiom axiom   = new Axiom();
            ICard  topCard = new Card(Colour.Blue, Number.Five, axiom);

            // ACT
            ArgumentOutOfRangeException argumentOutOfRangeException = null;
            IRuleScore ruleScore = null;

            try
            {
                ruleScore = new RuleScore(
                    numberOfCards: numberOfCards,
                    topCard: topCard);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                argumentOutOfRangeException = ex;
            }

            // ASSERT
            if (argumentOutOfRangeException != null)
            {
                Console.WriteLine(argumentOutOfRangeException.ToString());
            }

            Assert.IsNotNull(argumentOutOfRangeException, "Expected exception not thrown");
            Assert.IsNull(ruleScore, "ruleScore == null");
        }
Example #3
0
        public void TestCompareToNullThrowsException()
        {
            // ARRANGE
            IAxiom     axiom         = new Axiom();
            ICard      topCard       = new Card(Colour.Green, Number.Four, axiom);
            const int  numberOfCards = 4;
            IRuleScore ruleScore     = new RuleScore(numberOfCards, topCard);

            // ACT
            ArgumentNullException argumentNullException = null;
            int comparison = 99;

            try
            {
                comparison = ruleScore.CompareTo(null);
            }
            catch (ArgumentNullException exception)
            {
                argumentNullException = exception;
            }

            // ASSERT
            if (argumentNullException != null)
            {
                Console.WriteLine(argumentNullException.ToString());
            }

            Assert.IsNotNull(argumentNullException);
            Assert.AreEqual(expected: 99, actual: comparison);
        }
Example #4
0
        public void TestConstructorWithPositiveNumberOfCardsAndNullTopCard()
        {
            // ARRANGE
            const int numberOfCards = 1;

            // ACT
            ArgumentException argumentException = null;
            IRuleScore        ruleScore         = null;

            try
            {
                ruleScore = new RuleScore(
                    numberOfCards: numberOfCards,
                    topCard: null);
            }
            catch (ArgumentException ex)
            {
                argumentException = ex;
            }

            // ASSERT
            if (argumentException != null)
            {
                Console.WriteLine(argumentException.ToString());
            }

            Assert.IsNotNull(argumentException, "argumentException != null");
            Assert.IsNull(ruleScore, "ruleScore == null");
        }
Example #5
0
    public DumpWrapper Dump()
    {
        var ret = new DumpWrapper();

        ret.name           = Name;
        ret.minimalPLMDump = minimalPlayablePLM;
        ret.canvasDump     = CanvasConfig.StaticSerialize(canvasConfig);
        ret.matchRuleDumps = matchRules.SchemeStyleMap <RuleMatchBasic, string>((r) => {
            return(RuleMatchBasic.StaticSerialize(r));
        });
        ret.operationRuleDumps = operationRules.SchemeStyleMap <RuleOperation, string>((r) => {
            return(RuleOperation.StaticSerialize(r));
        });
        ret.extensionRuleDumps = extensionRules.SchemeStyleMap <RuleMatchExtension, string>((r) => {
            return(RuleMatchExtension.StaticSerialize(r));
        });
        ret.scoreRuleDumps = scoreRules.SchemeStyleMap <RuleScore, string>((r) => {
            return(RuleScore.StaticSerialize(r));
        });
        ret.refillRuleDump = RuleRefill.StaticSerialize(refillRule);
        ret.traitDumps     = slotConfig.Traits.SchemeStyleMap <SlotTrait, string>((t) => {
            return(SlotTrait.StaticSerialize(t));
        });
        ret.specialDumps = new List <string>();
        foreach (var kvp in slotConfig.Specials)
        {
            ret.specialDumps.Add(SlotSpecialty.StaticSerialize(kvp.Value));
        }
        return(ret);
    }
Example #6
0
        private void CalculateData()
        {
            //对每个股票进行分析
            StockSQL.DeleteRule();

            analyse_now = 0;
            foreach (StockData stockheader in StockApp.allstock.Values)
            {
                //初始化股票
                StockData stock = StockSQL.GetStockDetail_2(stockheader.code, stockheader.name);
                UtilLog.AddInfo(TAG, "Start to calculate " + stock.code);
                int stock_length = stock.items.Length;
                //第几个分析的股票
                analyse_now++;

                CalBuy(stock);
                CalSell(stock);

                prog.SetProgress(analyse_now * 100 / analyse_total);
                //释放内存
                if (analyse_now % 100 == 0)
                {
                    UtilLog.AddInfo(TAG, "Start to free memory");
                    GC.Collect();
                    UtilLog.AddInfo(TAG, "Free memory done!");
                    System.Threading.Thread.CurrentThread.Join(500);
                }
                UtilLog.AddInfo(TAG, analyse_now + "/" + analyse_total + ":" + stock.name + "(" + stock.code + ")" + " calculate finished ");
            }

            RuleScore.SetRuleScore();
            RuleScore.SetAllPreScore();
            lbl_status.Text = "Calculation Done";
        }
Example #7
0
        public void TestCompareWithZeroScore()
        {
            // ARRANGE
            IRuleScore ruleScore1 = new RuleScore(numberOfCards: 0, topCard: null);
            IRuleScore ruleScore2 = new RuleScore(numberOfCards: 0, null);

            // ACT
            int actualResult = ruleScore1.CompareTo(ruleScore2);

            // ASSERT
            Assert.AreEqual(expected: 0, actual: actualResult);
        }
Example #8
0
        public void TestConstructorWithZeroScore()
        {
            // ARRANGE
            const int numberOfCards = 0;

            // ACT
            IRuleScore ruleScore = new RuleScore(
                numberOfCards: numberOfCards,
                topCard: null);

            // ASSERT
            Assert.AreEqual(numberOfCards, ruleScore.NumberOfCards);
            Assert.IsNull(ruleScore.TopCard);
        }
Example #9
0
        public void TestConstructorWithActualScore()
        {
            // ARRANGE
            IAxiom    axiom         = new Axiom();
            const int numberOfCards = 5;
            ICard     topCard       = new Card(Colour.Red, Number.Seven, axiom);

            // ACT
            IRuleScore ruleScore = new RuleScore(
                numberOfCards: numberOfCards,
                topCard: topCard);

            // ASSERT
            Assert.AreEqual(numberOfCards, ruleScore.NumberOfCards);
            Assert.IsTrue(ruleScore.TopCard.CompareTo(topCard) == 0);
        }
Example #10
0
 private void InitFrom(DumpWrapper dump)
 {
     Name = dump.name;
     minimalPlayablePLM = dump.minimalPLMDump;
     canvasConfig       = CanvasConfig.StaticDeserialize(dump.canvasDump);
     slotConfig         = new SlotConfig();
     slotConfig.Init(dump.traitDumps, dump.specialDumps);
     matchRules = dump.matchRuleDumps.SchemeStyleMap <string, RuleMatchBasic>((str) => {
         return(RuleMatchBasic.StaticDeserialize(str));
     });
     operationRules = dump.operationRuleDumps.SchemeStyleMap <string, RuleOperation>((str) => {
         return(RuleOperation.StaticDeserialize(str));
     });
     extensionRules = dump.extensionRuleDumps.SchemeStyleMap <string, RuleMatchExtension>((str) => {
         return(RuleMatchExtension.StaticDeserialize(str));
     });
     scoreRules = dump.scoreRuleDumps.SchemeStyleMap <string, RuleScore>((str) => {
         return(RuleScore.StaticDeserialize(str));
     });
     refillRule = RuleRefill.StaticDeserialize(dump.refillRuleDump);
 }
Example #11
0
        public void TestCompareWithVariousCombinations(
            Colour topCard1Colour,
            Number topCard1Number,
            int numberOfCards1,
            int expectedResult)
        {
            // ARRANGE
            IAxiom axiom = new Axiom();

            ICard      topCard1   = new Card(topCard1Colour, topCard1Number, axiom);
            IRuleScore ruleScore1 = new RuleScore(numberOfCards1, topCard1);

            ICard      topCard2       = new Card(Colour.Green, Number.Four, axiom);
            const int  numberOfCards2 = 2;
            IRuleScore ruleScore2     = new RuleScore(numberOfCards2, topCard2);

            // ACT
            int actualResult = ruleScore1.CompareTo(ruleScore2);

            // ASSERT
            Assert.AreEqual(expectedResult, actualResult);
        }
Example #12
0
	public static string StaticSerialize(RuleScore r)
	{
		return JsonHelper.Serialize(new Tuple<string, string>(r.SerializeUID, r.Serialize()));
	}
Example #13
0
 public static string StaticSerialize(RuleScore r)
 {
     return(JsonHelper.Serialize(new Tuple <string, string>(r.SerializeUID, r.Serialize())));
 }