Пример #1
0
        public async Task <ActionResult <FizzBuzzRule> > PutFizzBuzzRule(long id, FizzBuzzRule fizzBuzzRule)
        {
            if (id != fizzBuzzRule.Id)
            {
                return(BadRequest());
            }

            var existingRule = await _context.FizzBuzzRules.FindAsync(id);

            try
            {
                if (existingRule == null)
                {
                    _context.FizzBuzzRules.Add(fizzBuzzRule);
                }
                else
                {
                    _context.Entry(existingRule).CurrentValues.SetValues(fizzBuzzRule);
                }
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(CreatedAtAction("GetFizzBuzzRule", new { id = fizzBuzzRule.Id }, fizzBuzzRule));
        }
Пример #2
0
        public void IsInvalidMultiple(int dividend, int divisor)
        {
            var fizzBuzzRule = new FizzBuzzRule();

            fizzBuzzRule.Divisor = divisor;

            Assert.False(fizzBuzzRule.IsMultiple(dividend));
        }
Пример #3
0
        public void Multiples_of_three_and_five_print_FizzBuzz()
        {
            var fizzBuzzRule = new FizzBuzzRule();

            Assert.True(fizzBuzzRule.Applies(15));
            Assert.True(fizzBuzzRule.Applies(30));
            Assert.True(fizzBuzzRule.Applies(45));
        }
Пример #4
0
        public void No_Multiples_of_three_and_five_print_not_FizzBuzz()
        {
            var fizzBuzzRule = new FizzBuzzRule();

            Assert.False(fizzBuzzRule.Applies(3));
            Assert.False(fizzBuzzRule.Applies(5));
            Assert.False(fizzBuzzRule.Applies(77));
        }
    // ≥ 3 battery holders present
    // Serial & parallel ports present
    // 3 letters & 3 digits in serial number
    // DVI & Stereo RCA ports present
    // ≥ 5 batteries present
    // None of the above
    // ≥ 2 strikes

    public List <FizzBuzzRule> GenerateRuleSet()
    {
        setupRuleSets();

        if (seed == 1)
        {
            return(new List <FizzBuzzRule> {
                ruleSet3[0].SetConfigs(3),
                ruleSet2[0],
                ruleSet2[1],
                ruleSet3[2].SetConfigs(KMBombInfoExtensions.KnownPortType.DVI, KMBombInfoExtensions.KnownPortType.StereoRCA, "DVI-D", "Stereo RCA"),
                ruleSet3[1].SetConfigs(5),
                ruleSet1[0]
            });
        }
        List <FizzBuzzRule> result = new List <FizzBuzzRule>();

        int ix1 = rnd.Next(0, ruleSet2.Count);
        int ix2;

        //ix2 = rnd.Next(0, ruleSet2.Count);
        do
        {
            ix2 = rnd.Next(0, ruleSet2.Count);
        } while (ix2 == ix1);
        result.Add(ruleSet2[ix1]);
        result.Add(ruleSet2[ix2]);

        ix1 = rnd.Next(0, ruleSet3.Count);
        int ix3;

        //ix2 = rnd.Next(0, ruleSet3.Count);
        //ix3 = rnd.Next(0, ruleSet3.Count);
        do
        {
            ix2 = rnd.Next(0, ruleSet3.Count);
        } while (ix2 == ix1);
        do
        {
            ix3 = rnd.Next(0, ruleSet3.Count);
        } while (ix3 == ix1 || ix3 == ix2);
        FizzBuzzRule rs3Rule1 = ruleSet3[ix1];
        FizzBuzzRule rs3Rule2 = ruleSet3[ix2];
        FizzBuzzRule rs3Rule3 = ruleSet3[ix3];

        rs3Rule1.SetConfigs(rs3Rule1.GenRule(rnd));
        rs3Rule2.SetConfigs(rs3Rule2.GenRule(rnd));
        rs3Rule3.SetConfigs(rs3Rule3.GenRule(rnd));
        result.Add(rs3Rule1);
        result.Add(rs3Rule2);
        result.Add(rs3Rule3);

        result.Shuffle(rnd);

        result.Add(ruleSet1[rnd.Next(0, ruleSet1.Count)]);

        return(result);
    }
        public MathAssistantApplication Create(RuleEnum ruleType)
        {
            ITransformRule transformRule = new FizzBuzzRule();

            if (ruleType == RuleEnum.Monkey)
            {
                transformRule = new MonkeyRule();
            }

            return(Create(transformRule));
        }
Пример #7
0
        public void RuleReturnsInvalidToken(int dividend, int divisor, string token)
        {
            var rule = new FizzBuzzRule {
                Divisor = divisor, Token = token
            };
            var rules = new List <FizzBuzzRule> {
                rule
            };

            string output = dividend.FizzBuzzCheck(rules);

            Assert.NotEqual(token, output);
        }
Пример #8
0
        private string FizzBuzzCheckRules(long value)
        {
            string result = "";
            var    rules  = _context.FizzBuzzRules.Where(r => ((value % r.Id) == 0));

            if (rules != null)
            {
                var count = rules.Count();
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        FizzBuzzRule rule = rules.ToList().ElementAt(i);
                        result += rule.ReplaceWith;
                    }
                }
                else
                {
                    result = value.ToString();
                }
            }
            return(result);
        }
        public void Answer_ContainsOfThree(string positive, string negative, uint input, string expect)
        {
            var target = new FizzBuzzRule(n => n.ToString().Contains("3") ? positive : negative);

            target.Answer(input).Is(expect);
        }
        public void Answer_MultipulesOfFifteen(string positive, string negative, uint input, string expect)
        {
            var target = new FizzBuzzRule(n => n % 15u == 0u ? positive : negative);

            target.Answer(input).Is(expect);
        }
Пример #11
0
    void FindSolutions()
    {
        var conditions = new bool[6];

        for (int i = 0; i < 5; i++)
        {
            FizzBuzzRule rule = ruleSet[i];
            if (rule.CheckRule != null)
            {
                conditions[i] = rule.CheckRule(BombInfo);
                Debug.LogFormat("[FizzBuzz #{0}] Condition '{1}': {2}", moduleId, rule.Id, conditions[i]);
            }
            else
            {
                conditions[i] = rule.CheckRuleWithConfigs(BombInfo, rule.Configs);
                Debug.LogFormat("[FizzBuzz #{0}] Condition '{1}' ({3}): {2}", moduleId, rule.Id, conditions[i], string.Join(", ", rule.Configs.Take(2).Select(x => x.ToString()).ToArray()));
            }
        }

        if (conditions.All(b => !b))
        {
            conditions[5] = true;
            Debug.LogFormat("[FizzBuzz #{0}] Condition '{1}': {2}", moduleId, "NoOtherConditionsMet", true);
        }

        foreach (var variableRule in new[] { false, true })
        {
            var solution = new int[3];
            for (int n = 0; n < 3; n++)
            {
                int addNum = 0;

                // Add up the numbers for all conditions
                for (int i = 0; i < 6; i++)
                {
                    // If two strikes, add the number for “VariableRule” _instead of_ the one for “NoOtherConditionsMet”
                    if (i == 5 && variableRule)
                    {
                        addNum += table[6, Colors[n]];
                    }
                    else if (conditions[i])
                    {
                        addNum += table[i, Colors[n]];
                    }
                }

                int num       = 0;
                int beforeNum = 0;
                for (int i = 0; i < 7; i++)
                {
                    beforeNum *= 10;
                    beforeNum += Nums[n][i];

                    num *= 10;
                    num += (Nums[n][i] + addNum) % 10;
                }

                solution[n] = (num % divisibilityRules[0] == 0 ? 1 : 0) + (num % divisibilityRules[1] == 0 ? 2 : 0);

                Debug.LogFormat("[FizzBuzz #{0}] Button {1} ({2}) [{3}: {4}]:", moduleId, n + 1, ColorNames[Colors[n]], ruleSet[5].Id, variableRule);
                Debug.LogFormat("[FizzBuzz #{0}] — original number is {1}", moduleId, beforeNum);
                Debug.LogFormat("[FizzBuzz #{0}] — adding number is {1}", moduleId, addNum);
                Debug.LogFormat("[FizzBuzz #{0}] — final number is {1}", moduleId, num);
                Debug.LogFormat("[FizzBuzz #{0}] — solution is {1}", moduleId, StateNames[solution[n]]);
            }
            Solutions[variableRule ? 1 : 0] = solution;
            Debug.LogFormat("[FizzBuzz #{0}] Solution for [{1}: {2}] is [{3}, {4}, {5}].", moduleId, ruleSet[5].Id, variableRule, StateNames[solution[0]], StateNames[solution[1]], StateNames[solution[2]]);
        }
    }