Ejemplo n.º 1
0
        public void TestSearch()
        {
            // make a collection
            atomCollection search_collection = new atomCollection();

            // add some nodes to the collection
            const int no_of_nodes = 10;
            for (int i = 0; i < no_of_nodes; i++)
            {
                node n = new node();
                n.SetImportance(1.0f - (i / (float)no_of_nodes), atom.SHORT_TERM_IMPORTANCE);
                search_collection.Add(n);
            }

            // create a search agent
            agentSearch seeker = new agentSearch(search_collection, "importance",
                                                 atom.SHORT_TERM_IMPORTANCE);

            // create an exemplar to match against
            node exemplar = new node();
            exemplar.SetImportance(0.7f, atom.SHORT_TERM_IMPORTANCE);

            // link the exemplar to the the search agent
            bool link_added = seeker.AddIncomingLink("hebbian", exemplar, new truthvalue());
            Assert.IsTrue(link_added, "Link created");

            // run the agent until it completes
            seeker.Run();
            while (seeker.running) seeker.Run();
            atomCollection search_results = seeker.GetSearchResults();

            // check that some results were produced
            Assert.IsNotNull(search_results, "search results were returned");
            if (search_results != null)
            {
                // check that the number of nodes is what we expect
                Assert.AreEqual(search_results.Count(), no_of_nodes, "expected number of nodes in the search pool");

                //check that the results are sorted
                int i = 1;
                bool in_order = true;

                while ((i < search_results.Count()) && (in_order))
                {
                    if (seeker.GetDifference(i) < seeker.GetDifference(i - 1)) in_order = false;
                    i++;
                }
                Assert.IsTrue(in_order, "search results are sorted in ascending order of difference from the exemplar");
            }
        }