Пример #1
0
        public void AlchemyControllerCanAddNewElement()
        {
            var rs = new RuleSet();
            var controller = new AlchemyController( rs );
            const string element = "aoeu";
            controller.RegisterNewElement( element );

            Assert.AreEqual( 1, rs.FoundElements.Count() );
            Assert.AreEqual( element, rs.FoundElements.First().Name );
        }
Пример #2
0
        public void AlchemyControllerRecommendsEmptyRuleIfDone()
        {
            var rs = new RuleSet();
            var controller = new AlchemyController( rs );
            controller.RegisterNewElement( "fire" );
            var rule = controller.RecommendNewRule();
            controller.ReportChangedRule( rule );

            var finalRule = controller.RecommendNewRule();

            Assert.AreEqual( Rule.EmptyRule, finalRule );
        }
Пример #3
0
        public void AlchemyControllerCanMarkElementAsTerminal()
        {
            var rs = new RuleSet();
            var a = new AlchemyController( rs );

            a.RegisterNewElement( "a" );
            a.RegisterNewElement( "b" );
            a.RegisterNewElement( "c" );
            a.RegisterNewElement( "d" );
            a.RegisterNewElement( "e" );

            a.FinalizeElement( "c" );

            var em = rs.FoundElements.FirstOrDefault( e => e.Name.Equals( "c" ) );

            Assert.IsTrue( em.TerminalSpecified );
            Assert.IsTrue( em.TerminalValue.HasValue );
            if( em.TerminalValue != null )
            {
                Assert.IsTrue( em.TerminalValue.Value );
            }
            Assert.AreEqual( 1, rs.FoundElements.Count( e => e.TerminalValue.HasValue && e.Terminal ) );
            Assert.AreEqual( 4, rs.FoundElements.Count( e => !e.TerminalValue.HasValue ) );
        }
Пример #4
0
        public void RuleSetNotifiesOnPropertyChanged()
        {
            var changedprops = new List<string>();
            var r = new RuleSet();
            r.PropertyChanged += ( s, e ) => changedprops.Add( e.PropertyName );

            var controller = new AlchemyController( r );
            controller.RegisterNewElement( "fire" );
            var rule = controller.RecommendNewRule();
            rule.Result = new[] { new Element( "water" ) };

            controller.ReportChangedRule( rule );

            Assert.AreEqual( 2, changedprops.Count( p => p.Equals( "FoundElements" ) ) );
            Assert.AreEqual( 2, r.FoundElements.Count() );
            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "Rules" ) ) );
            Assert.AreEqual( 1, r.Rules.Count() );
        }
Пример #5
0
        public void AlchemyControllerWontReccomendRuleWithTerminalElements()
        {
            var rs = new RuleSet();
            var a = new AlchemyController( rs );

            a.RegisterNewElement( "a" );
            a.RegisterNewElement( "b" );
            a.RegisterNewElement( "c" );
            a.FinalizeElement( "a" );

            var rules = new List<Rule>();
            for( int i = 0; i < 100; i++ )
            {
                var r1 = a.RecommendNewRule();
                if( r1 == Rule.EmptyRule )
                    break;
                rules.Add( r1 );
                a.ReportChangedRule( r1 );
            }

            Assert.AreEqual( 3, rules.Count );
            Assert.IsFalse( rules.Any( r => r.Ingredients.Any( i => i.Name.Equals( a ) ) ) );
        }
Пример #6
0
 public void ExtensiveControllerRoundtripMonkeyTest()
 {
     var rs = new RuleSet();
     var c = new AlchemyController( rs );
     c.RegisterNewElement( "fire" );
     c.RegisterNewElement( "water" );
     c.RegisterNewElement( "burn" );
 }
Пример #7
0
        public void ControllerRecommendsCombinationsButNotDuplicates()
        {
            var rs = new RuleSet();
            var c = new AlchemyController( rs );
            c.RegisterNewElement( "a" );
            c.RegisterNewElement( "mb" );
            c.RegisterNewElement( "aoeu" );
            c.ReportChangedRule( c.RecommendNewRule() );

            var rules = new List<Rule>();
            for( int i = 0; i < 100; i++ )
            {
                var r1 = c.RecommendNewRule();
                if( r1 == Rule.EmptyRule )
                    break;
                rules.Add( r1 );
                c.ReportChangedRule( r1 );
            }

            Assert.AreEqual( 5, rules.Count );
        }
Пример #8
0
        public void ControllerRecommendsAllPossibleCombinationsOfElements()
        {
            const string e1 = "1";
            const string e2 = "2";
            var rs = new RuleSet();
            var c = new AlchemyController( rs );
            c.RegisterNewElement( e1 );
            c.RegisterNewElement( e2 );
            var rules = new List<Rule>();
            for( int i = 0; i < 100; i++ )
            {
                var r1 = c.RecommendNewRule();
                if( r1 == Rule.EmptyRule )
                    break;
                rules.Add( r1 );
                c.ReportChangedRule( r1 );
            }

            Assert.AreEqual( 3, rules.Count );
            Assert.IsTrue( AssertForCombo( e1, e1, rules ) );
            Assert.IsTrue( AssertForCombo( e1, e2, rules ) );
            Assert.IsTrue( AssertForCombo( e2, e2, rules ) );
        }
Пример #9
0
        public void CanReportTestedRuleBackToController()
        {
            var rs = new RuleSet();
            var controller = new AlchemyController( rs );
            controller.RegisterNewElement( "fire" );
            var rule = controller.RecommendNewRule();
            rule.Result = new[] { new Element( "water" ) };

            controller.ReportChangedRule( rule );

            Assert.AreEqual( 1, rs.Rules.Count() );
            Assert.AreEqual( 2, rs.FoundElements.Count() );
        }