コード例 #1
0
        public void Shoul_Generate_11_Integer_Values()
        {
            var result = RangeGenerator.Create(0, 10, 10);

            Assert.AreEqual(11, result.Count);
            Assert.AreEqual(0, result[0]);
            Assert.AreEqual(3, result[3]);
        }
コード例 #2
0
        public void Generator_ForSequence2()
        {
            int[] expected = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
            var   func     = new Func <int, int, int>(
                (beforePrevious, previous) => (6 * previous - 8 * beforePrevious));
            var generator = new RangeGenerator <int>(1, 2, func, 10);

            CollectionAssert.AreEqual(expected, generator.ToArray());
        }
コード例 #3
0
        public void Generator_ForSequence1()
        {
            int[] expected = { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 };
            var   func     = new Func <int, int, int>(
                (beforePrevious, previous) => beforePrevious + previous);
            var generator = new RangeGenerator <int>(1, 1, func, 10);

            CollectionAssert.AreEqual(expected, generator.ToArray());
        }
コード例 #4
0
        public void Should_Generate_11_Double_Values()
        {
            var result = RangeGenerator.Create(0d, 1d, 10);

            Assert.AreEqual(11, result.Count);
            Assert.AreEqual(0, result[0]);
            Assert.AreEqual(0.4, result[4]);
            //Fail
            Assert.IsTrue(Math.Abs(0.3 - result[3]) < 1e-8);
        }
コード例 #5
0
    public static void Main(string[] args)
    {
        using (StreamReader reader = File.OpenText("B-large-practice.in"))
        {
            using (StreamWriter writer = File.CreateText("B-large-practice.out"))
            {
                var T = int.Parse(reader.ReadLine());
                for (var iteration = 1; iteration <= T; iteration++)
                {
                    var input = reader.ReadLine().Split(' ');
                    //sizes of packets that need to be filled
                    var packetSizes = reader.ReadLine().Split(' ');
                    //number of ingredients
                    var N = int.Parse(input[0]);
                    //number of packages
                    var P = int.Parse(input[1]);

                    var ranges = new Queue <RangeGenerator> [N];

                    //for each of the ingredients
                    for (var i = 0; i < N; i++)
                    {
                        //create a container to whole the range of ingredient options
                        var ingredientQueue = new List <RangeGenerator>();
                        //get the packet size
                        var packet = int.Parse(packetSizes[i]);
                        //get all of the available ingredients to use
                        var availableMass = reader.ReadLine().Split(' ');

                        //for each package
                        for (var j = 0; j < P; j++)
                        {
                            //see how much we have to work with
                            var mass = int.Parse(availableMass[j]);
                            //return the possible range of packets we can pack with the 10% delta
                            var range = RangeGenerator.For(packet, mass);
                            //if we have a valid range, add to the ingredient queue
                            if (range != null)
                            {
                                ingredientQueue.Add(range);
                            }
                        }

                        //sort the ingredient queue from smallest to largest
                        ingredientQueue.Sort();
                        //add the ingredient queue to the range container in a queue we will use later
                        ranges[i] = new Queue <RangeGenerator>(ingredientQueue);
                    }

                    writer.Write("Case #{0}: {1}\n", iteration, Solve(ranges));
                }
            }
        }
    }
コード例 #6
0
        public void Generator_ForSequence3()
        {
            double[] expected = { 1, 2, 2.5, 3.3, 4.05757575757576, 4.87086926018965, 5.70389834408211, 6.55785277425587, 7.42763417076325, 8.31053343902137 };
            var      func     = new Func <double, double, double>(
                (beforePrevious, previous) => (previous + (beforePrevious / previous)));
            var generator = new RangeGenerator <double>(1, 2, func, 10);
            int i         = 0;

            foreach (var number in generator)
            {
                Assert.AreEqual(expected[i++], number, 0.0000001);
            }
        }
        public void Generate_65000To66000With66001_Fail()
        {
            // Assemble
            int    min        = 65000;
            int    max        = 66000;
            string testString = "some text 66001 to test";

            // Act
            string regexPattern = RangeGenerator.Generate(min, max);

            // Assert
            Regex regex = new Regex(regexPattern);

            Assert.IsFalse(regex.IsMatch(testString));
        }
        public void Generate_777To888With899_Fail()
        {
            // Assemble
            int    min        = 777;
            int    max        = 888;
            string testString = "some text 899 to test";

            // Act
            string regexPattern = RangeGenerator.Generate(min, max);

            // Assert
            Regex regex = new Regex(regexPattern);

            Assert.IsFalse(regex.IsMatch(testString));
        }
        public void AdhocTest()
        {
            // Assemble
            int    min        = 3493;
            int    max        = 5765;
            string testString = "some text 3555 to test";

            // Act
            string regexPattern = RangeGenerator.Generate(min, max);

            // Assert
            Regex regex = new Regex(regexPattern);

            Assert.IsTrue(regex.IsMatch(testString));
        }
        public void Generate_1To100With99_Pass()
        {
            // Assemble
            int    min        = 1;
            int    max        = 100;
            string testString = "some text 99 to test";

            // Act
            string regexPattern = RangeGenerator.Generate(min, max);

            // Assert
            Regex regex = new Regex(regexPattern);

            Assert.IsTrue(regex.IsMatch(testString));
        }
        public void Generate_Random_Pass()
        {
            // Assemble
            for (int i = 0; i < 1000; i++)
            {
                int    absoluteMax = 10000;
                int    min         = new Random().Next(1, absoluteMax);
                int    max         = new Random().Next(min, absoluteMax);
                int    testNumber  = new Random().Next(min, max);
                string testString  = $"some text {testNumber} to test";

                // Act
                string regexPattern = RangeGenerator.Generate(min, max);

                // Assert
                Regex regex = new Regex(regexPattern);

                if (!regex.IsMatch(testString))
                {
                    throw new Exception();
                }
            }
        }
コード例 #12
0
ファイル: Range.cs プロジェクト: krpaul/Eeloo
        public override eeObject VisitRangeExp([NotNull] EelooParser.RangeExpContext ctx)
        {
            // add this to scope
            Interpreter.currentScope.scopeCtx = ctx;

            EelooParser.ExpContext[] exps = ctx.exp();

            eeObject exp1 = Visit(exps[0]),
                     exp2 = Visit(exps[1]);

            if (exp1.AsNumber() == null || exp2.AsNumber() == null)
            {
                throw new Exception("TO DO");
            }

            eeNumber start = exp1.AsNumber(),
                     stop  = exp2.AsNumber();

            ICollection <eeObject> rangeObj;

            if (exps.Length == 2) // only two numbers provided, assume step is 1
            {
                rangeObj = RangeGenerator.Generate(start, stop, eeNumber.ONE);
            }
            else
            {
                rangeObj = RangeGenerator.Generate(start, stop, Visit(exps[2]).AsNumber());
            }

            eeObject exprList = new eeObject(rangeObj)
            {
                type = eeObjectType.internal_EXPRLIST
            };

            return(eeObject.newListObject(exprList));
        }