Exemplo n.º 1
0
 public void AllUIItemsHaveDefaultConstructor()
 {
     var collection = new List<string>();
     AllSubsclassesHaveEmptyConstructor(collection, typeof(UIItem));
     AllSubsclassesHaveEmptyConstructor(collection, typeof(SearchCondition));
     AllSubsclassesHaveEmptyConstructor(collection, typeof(SearchCriteria));
     AllSubsclassesHaveEmptyConstructor(collection, typeof(AutomationElementProperty));
     Assert.AreEqual(0, collection.Count, collection.ToString());
 }
 public void TestGetMinion()
 {
     Villain test = ObjectMother.TestVillain();
     test.addMinion(ObjectMother.TestMinion());
     List<Minion> testList = new List<Minion>();
     testList.Add(ObjectMother.TestMinion());
     List<Minion> actual = test.getMinions();
     Assert.AreEqual(actual.ToString(), testList.ToString());
 }
Exemplo n.º 3
0
        public void Hand_TestToString_CheckIfCorrectInput()
        {
            var listOfCards = new List<ICard>();
            while (listOfCards.Count==10)
            {
                listOfCards.Add(new Card(new CardFace(), new CardSuit()));
            }

            Assert.IsNotEmpty(listOfCards.ToString());
        }
Exemplo n.º 4
0
        public void LetsGetSomeMatchesGoingOn()
        {
            var users = new List<User>();

            var filler = new Filler();
            filler.Configure<Bar>().Defaults();
            filler.Configure<Foo>(config =>
            {
                config.For(foo => foo.Bars).Times(Constants.Random.Next(100));
                config.For(foo => foo.Age).Use(new RandomWholeNumberGenerator(10, 21)).Order(1);
                config.For(foo => foo.CalculatedAge).Do(context => context.CurrentAs<Foo>().Age + 20).Order(2);
            }).Defaults();

            filler.Configure<Goo>().Defaults();
            filler.Configure<User>().Defaults();
            filler.Configure<AllowedPartner>(config =>
            {
                config.For(allowedPartner => allowedPartner.MinAge).Use(new MinAgeGenerator());
                config.For(allowedPartner => allowedPartner.MaxAge).Use(new MaxAgeGenerator());
            });

            1000.Times(() => users.Add(filler.Fill(new User())));
            users.ToString();
        }
Exemplo n.º 5
0
        public void testLargeBulkInsert()
        {
            IDBCollection c = Mongo.DefaultDatabase.GetCollection("largebulk");
            c.Drop();
            string test = "asdasdasd";
            while (test.Length < 10000)
                test += test;
            List<IDBObject> l = new List<IDBObject>();
            int num = 3 * (Bytes.MAX_OBJECT_SIZE / test.Length);

            for (int t = 0; t < num; t++)
            {
                l.Add(new Document("test", t));
            }
            Assert.AreEqual(0, c.Find().Count());
            c.Insert(new Document("l",l));
            Assert.AreEqual(num, c.Find().Count());

            test = l.ToString();
            Assert.IsTrue(test.Length > Bytes.MAX_OBJECT_SIZE);
            Assert.That(()=> c.Save(new Document("foo", test)), Throws.Exception);
            Assert.AreEqual(num, c.Find().Count());
        }
Exemplo n.º 6
0
        public void GetTemplatesTests()
        {
            const string foo1 = "{{foo|a}}", foo2 = "{{foo|b}}";
            string text = @"now " + foo1 + " and " + foo2;

            Regex foo = new Regex(@"{{foo.*?}}");
            List<Match> fred = new List<Match>();

            foreach (Match m in foo.Matches(text))
                fred.Add(m);

            Assert.AreEqual(fred.ToString(), Parsers.GetTemplates(text, "foo").ToString());
            Assert.AreEqual(fred.ToString(), Parsers.GetTemplates(text, "Foo").ToString());
            List<Match> templates = Parsers.GetTemplates(text, "foo");
            Assert.AreEqual(foo1, templates[0].Value);
            Assert.AreEqual(foo2, templates[1].Value);
            Assert.AreEqual(2, templates.Count);

            // ignores commeted out templates
            templates = Parsers.GetTemplates(text + @" <!-- {{foo|c}} -->", "foo");
            Assert.AreEqual(foo1, templates[0].Value);
            Assert.AreEqual(foo2, templates[1].Value);
            Assert.AreEqual(2, templates.Count);

            // ignores nowiki templates
            templates = Parsers.GetTemplates(text + @" <nowiki> {{foo|c}} </nowiki>", "foo");
            Assert.AreEqual(foo1, templates[0].Value);
            Assert.AreEqual(foo2, templates[1].Value);
            Assert.AreEqual(2, templates.Count);

            // nested templates caught
            const string foo3 = @"{{ Foo|bar={{abc}}|beer=y}}";
            templates = Parsers.GetTemplates(@"now " + foo3 + @" there", "foo");
            Assert.AreEqual(foo3, templates[0].Value);

            // whitespace ignored
            const string foo4 = @"{{ Foo }}";
            templates = Parsers.GetTemplates(@"now " + foo4 + @" there", "foo");
            Assert.AreEqual(foo4, templates[0].Value);

            // no matches here
            templates = Parsers.GetTemplates(@"now " + foo3 + @" there", "fo");
            Assert.AreEqual(0, templates.Count);

            templates = Parsers.GetTemplates(@"{{test}}", "test");
            Assert.AreEqual(1, templates.Count);

            templates = Parsers.GetTemplates(@"{{test}}
", "test");
            Assert.AreEqual(1, templates.Count);
        }
Exemplo n.º 7
0
        public void LoadDatedTemplates()
        {
            List<string> DatedTemplates = new List<string>();

            Assert.AreEqual(DatedTemplates, Parsers.LoadDatedTemplates(""), "returns empty list when no rules present");

            Assert.AreEqual(DatedTemplates, Parsers.LoadDatedTemplates("<!--{{tl|wikif-->"), "ignores commented out rules");

            DatedTemplates.Add("Wikify");
            Assert.AreEqual(DatedTemplates.ToString(), Parsers.LoadDatedTemplates(@"{{tl|wikify}}").ToString(), "loads single rule");

            DatedTemplates.Add("Citation needed");
            Assert.AreEqual(DatedTemplates.ToString(), Parsers.LoadDatedTemplates(@"{{tl|wikify}}
{{tl|citation needed}}").ToString(), "loads multiple rules");
        }
Exemplo n.º 8
0
        public void TestToString()
        {
            var stringCollection = new List<string>
            {
                 "This",
                 "is",
                 "a",
                 "comma",
                 "seperated",
                 "list",

            };

            var emptyStringCollection = new List<string>();
            List<string> nullStringCollection = null;
            Assert.AreEqual("This,is,a,comma,seperated,list", stringCollection.ToString(""));
            Assert.AreEqual("This,is,a,comma,seperated,list", stringCollection.ToString("Base string: "));
            Assert.AreEqual("", emptyStringCollection.ToString("EMPTY"));
            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.AreEqual("EMPTY", nullStringCollection.ToString("EMPTY"));
        }
        public void TestInjectImages_Trivial()
        {
            AlbumDescriptor ad = new AlbumDescriptor() 
            { Artist="ATeste",Name="Name1" };

            List<TrackDescriptor> lt = new List<TrackDescriptor>();
            lt.Add(new TrackDescriptor(){Name="T1",TrackNumber=47,Duration=TimeSpan.FromMinutes(2)});
            ad.RawTrackDescriptors = lt;

            lt.ToString().Should().NotBeNull();

            AlbumDescriptor ad2 = new AlbumDescriptor();
            ad.InjectImages(ad2,false);
            ad.RawImages.Should().BeNull();


            ad.InjectImages(null, false);
            ad.RawImages.Should().BeNull();
        }
Exemplo n.º 10
0
        public void TestPipelineXMLSnippet()
        {
            // SrcML sample method
            string srcmlOutput = @"<function><type><name> bool </name></type> <name> findInFiles </name><parameter_list> () </parameter_list>
                            <block>{
                                <decl_stmt><decl><type><specifier>const</specifier> <name>TCHAR</name> <modifier>*</modifier></type><name>dir2Search</name> <init>= <expr><call><name><name>_findReplaceDlg</name><operator>.</operator><name>getDir2Search</name></name><argument_list>()</argument_list></call></expr></init></decl>;</decl_stmt>

                                <expr_stmt><expr><call><name>findFilesInOut</name><argument_list>()</argument_list></call></expr>;</expr_stmt>
                                <if>if <condition>(<expr><operator>!</operator><name><name>dir2Search</name><index>[<expr><literal type=""number"">0</literal></expr>]</index></name> <operator>||</operator> <operator>!</operator><call><name><operator>::</operator><name>PathFileExists</name></name><argument_list>(<argument><expr><name>dir2Search</name></expr></argument>)</argument_list></call></expr>)</condition><then>
                                <block>{
                                    <return>return <expr><literal type = ""boolean"" > false </literal></expr>;</return>
                                }</block></then></if>
                                <decl_stmt><decl><type><name>string</name></type> <name>findString</name> <init>= <expr><literal type = ""string"" > """" </literal ></expr ></init ></decl >;</decl_stmt>

                                <expr_stmt><expr><call><name>gethurry</name><argument_list>()</argument_list></call></expr>;</expr_stmt>

                                <macro><name>findInOne</name><argument_list>(<argument>int a</argument>, <argument>findString</argument>)</argument_list></macro><empty_stmt>;</empty_stmt>

                                <decl_stmt><decl><type><name>bool</name></type> <name>isRecursive</name> <init>= <expr><call><name><name>_findReplaceDlg</name><operator >.</operator><name>isRecursive</name></name><argument_list>()</argument_list></call></expr></init></decl>;</decl_stmt>
                                <decl_stmt><decl><type><name>bool</name></type> <name>isInHiddenDir</name> <init>= <expr><call><name><name>_findReplaceDlg</name><operator >.</operator><name>isInHiddenDir</name></name><argument_list>()</argument_list></call></expr></init></decl>;</decl_stmt>

                                <if>if <condition>(<expr><call><name><name>a</name><operator >.</operator><name>size</name></name><argument_list>()</argument_list></call> <operator >==</operator> <literal type = ""number"" > 0 </literal></expr>)</condition><then>
                                <block>{
                                    <expr_stmt><expr><call><name><name>a</name><operator >.</operator><name>setFindInFilesDirFilter</name></name><argument_list>(<argument><expr><literal type = ""string""> ""dddd"" </literal ></expr ></argument>, <argument><expr><call><name>TEXT</name><argument_list>(<argument><expr><literal type = ""string"" > ""*.*"" </literal ></expr></argument>)</argument_list></call></expr></argument>)</argument_list></call></expr>;</expr_stmt>
                                    <expr_stmt><expr><call><name><name>a</name><operator >.</operator><name>getPatterns</name></name><argument_list>(<argument><expr><name>findString</name></expr></argument>)</argument_list></call></expr>;</expr_stmt>
                                }</block></then></if>
                                <return>return <expr><literal type = ""boolean"" > true </literal ></expr>;</return>
                            }</block></function>";

            // Convert raw string to MethodDefinition
            var fileSetup = new SrcMLFileUnitSetup(Language.CPlusPlus);
            var parser = new CPlusPlusCodeParser();

            var fileUnit = fileSetup.GetFileUnitForXmlSnippet(srcmlOutput, "sampletestmethods.cpp");
            var scope = parser.ParseFileUnit(fileUnit);

            var srcmlMethod = scope.GetDescendants<MethodDefinition>().First();

            // Verify the method definition
            Assert.IsInstanceOf<MethodDefinition>(srcmlMethod, "MethodDefinition found.");
            Console.WriteLine(srcmlMethod.ToString());

            // Extract SUnit Statements from MethodDefinition
            var statements = new List<Statement>();
            statements.AddRange(SUnitExtractor.ExtractEnding(srcmlMethod));
            statements.AddRange(SUnitExtractor.ExtractSameAction(srcmlMethod));
            statements.AddRange(SUnitExtractor.ExtractVoidReturn(srcmlMethod));

            // verify the statements selected
            Assert.IsNotEmpty(statements, "statements selected from method definition");
            Console.WriteLine(statements.ToString());

            // Translate Statements into SUnits
            List<SUnit> sunits = statements.ConvertAll(
                        new Converter<Statement, SUnit> (SUnitTranslator.Translate) );

            // verify sunits have been translated
            Assert.That(sunits.TrueForAll(s => s.action != null), "All SUnits initialized.");
            Console.WriteLine(sunits.ToString());

            // Generate text from SUnits
            List<string> sentences = sunits.ConvertAll(
                        new Converter<SUnit, string> (TextGenerator.GenerateText) );

            // verify string generated
            Assert.That(sentences.TrueForAll(s => s.Length > 0));
            Console.WriteLine(sentences);

            // Collect text and summarize
            var methodDocument = String.Join<string>(" ", sentences);
            var summary = Summarizer.Summarize(methodDocument);

            // verify summary
            Assert.That(! summary.Equals(""));
            Console.WriteLine(summary);
        }
Exemplo n.º 11
0
		public void ToString_EqualsName()
		{
			var list = new List { Name = "a name" };

			Assert.That(list.ToString(), Is.EqualTo("a name"));
		}
        public virtual void TestRandom()
        {
            string[] tokens = GetRandomTokens(10);
            Store.Directory indexDir = NewDirectory();
            Store.Directory taxoDir = NewDirectory();

            RandomIndexWriter w = new RandomIndexWriter(Random(), indexDir);
            var tw = new DirectoryTaxonomyWriter(taxoDir);
            FacetsConfig config = new FacetsConfig();
            int numDocs = AtLeast(1000);
            int numDims = TestUtil.NextInt(Random(), 1, 7);
            IList<TestDoc> testDocs = GetRandomDocs(tokens, numDocs, numDims);
            foreach (TestDoc testDoc in testDocs)
            {
                Document doc = new Document();
                doc.Add(NewStringField("content", testDoc.content, Field.Store.NO));
                testDoc.value = Random().NextFloat();
                doc.Add(new FloatDocValuesField("value", testDoc.value));
                for (int j = 0; j < numDims; j++)
                {
                    if (testDoc.dims[j] != null)
                    {
                        doc.Add(new FacetField("dim" + j, testDoc.dims[j]));
                    }
                }
                w.AddDocument(config.Build(tw, doc));
            }

            // NRT open
            IndexSearcher searcher = NewSearcher(w.Reader);

            // NRT open
            var tr = new DirectoryTaxonomyReader(tw);

            ValueSource values = new FloatFieldSource("value");

            int iters = AtLeast(100);
            for (int iter = 0; iter < iters; iter++)
            {
                string searchToken = tokens[Random().Next(tokens.Length)];
                if (VERBOSE)
                {
                    Console.WriteLine("\nTEST: iter content=" + searchToken);
                }
                FacetsCollector fc = new FacetsCollector();
                FacetsCollector.Search(searcher, new TermQuery(new Term("content", searchToken)), 10, fc);
                Facets facets = new TaxonomyFacetSumValueSource(tr, config, fc, values);

                // Slow, yet hopefully bug-free, faceting:
                var expectedValues = new List<Dictionary<string, float?>>();
                for (int i = 0; i < numDims; i++)
                {
                    expectedValues[i] = new Dictionary<string, float?>();
                }

                foreach (TestDoc doc in testDocs)
                {
                    if (doc.content.Equals(searchToken))
                    {
                        for (int j = 0; j < numDims; j++)
                        {
                            if (doc.dims[j] != null)
                            {
                                float? v = expectedValues[j][doc.dims[j]];
                                if (v == null)
                                {
                                    expectedValues[j][doc.dims[j]] = doc.value;
                                }
                                else
                                {
                                    expectedValues[j][doc.dims[j]] = (float)v + doc.value;
                                }
                            }
                        }
                    }
                }

                IList<FacetResult> expected = new List<FacetResult>();
                for (int i = 0; i < numDims; i++)
                {
                    IList<LabelAndValue> labelValues = new List<LabelAndValue>();
                    float totValue = 0;
                    foreach (KeyValuePair<string, float?> ent in expectedValues[i])
                    {
                        labelValues.Add(new LabelAndValue(ent.Key, ent.Value.Value));
                        totValue += ent.Value.Value;
                    }
                    SortLabelValues(labelValues);
                    if (totValue > 0)
                    {
                        expected.Add(new FacetResult("dim" + i, new string[0], totValue, labelValues.ToArray(), labelValues.Count));
                    }
                }

                // Sort by highest value, tie break by value:
                SortFacetResults(expected);

                IList<FacetResult> actual = facets.GetAllDims(10);

                // Messy: fixup ties
                SortTies(actual);

                if (VERBOSE)
                {
                    Console.WriteLine("expected=\n" + expected.ToString());
                    Console.WriteLine("actual=\n" + actual.ToString());
                }

                AssertFloatValuesEquals(expected, actual);
            }

            IOUtils.Close(w, tw, searcher.IndexReader, tr, indexDir, taxoDir);
        }