public void TwoDomains()
        {
            int[]   array  = new int[] { 1, 2, 3 };
            IDomain domain = Domains.ToDomain(array);

            string[] array2  = new string[] { "hello", "world" };
            IDomain  domain2 = Domains.ToDomain(array2);

            object[] results = new object[array.Length * array2.Length];
            for (int i = 0; i < array.Length; ++i)
            {
                for (int j = 0; j < array2.Length; ++j)
                {
                    results[i * array2.Length + j] = new object[] { array[i], array2[j] };
                }
            }

            int k = 0;

            foreach (ITuple tuple in Products.Cartesian(domain, domain2))
            {
                object[] result = (object[])results[k];
                Assert.AreEqual(result[0], tuple[0]);
                Assert.AreEqual(result[1], tuple[1]);
                ++k;
            }
            Assert.AreEqual(k, array.Length * array2.Length);
        }
        public void SingleDomain()
        {
            int[]   array  = new int[] { 1, 2, 3 };
            IDomain domain = Domains.ToDomain(array);

            int i = 0;

            foreach (ITuple tuple in Products.Cartesian(domain))
            {
                Assert.AreEqual(array[i], tuple[0]);
                ++i;
            }
            Assert.AreEqual(i, array.Length);
        }
Example #3
0
        public static IDomainCollection Uniformize(IDomainCollection domains)
        {
            if (domains == null)
            {
                throw new ArgumentNullException("domains");
            }

            Random rnd = new Random((int)DateTime.Now.Ticks);
            // find max
            int maxCount = int.MinValue;
            int minCount = int.MaxValue;

            foreach (IDomain domain in domains)
            {
                maxCount = Math.Max(maxCount, domain.Count);
                minCount = Math.Max(minCount, domain.Count);
            }

            if (minCount == maxCount)
            {
                return(domains);
            }

            DomainCollection udomains = new DomainCollection();

            foreach (IDomain domain in domains)
            {
                if (domain.Count == maxCount)
                {
                    udomains.Add(domain);
                    continue;
                }

                Object[] udomain = new Object[maxCount];
                int      i;
                for (i = 0; i < domain.Count; ++i)
                {
                    udomain[i] = domain[i];
                }
                for (; i < maxCount; ++i)
                {
                    udomain[i] = domain[rnd.Next(domain.Count)];
                }
                udomains.Add(Domains.ToDomain(udomain));
            }
            return(udomains);
        }
Example #4
0
        private void TestProblem(int k, int l)
        {
            // create domains
            DomainCollection domains = new DomainCollection();

            for (int i = 0; i < k; ++i)
            {
                int[] domain = new int[l];
                for (int j = 0; j < l; ++j)
                {
                    domain[j] = j;
                }
                domains.Add(Domains.ToDomain(domain));
            }
            // iterface
            ITupleEnumerable tuples = Products.PairWize(domains);
            int f = 1;

            foreach (ITuple tuple in tuples)
            {
                Console.WriteLine("{0}: {1}", f++, tuple);
            }
        }