public void TestGetResult_Empty()
        {
            BigInteger[] data = {};
            FibonacciResultSet testSet = new FibonacciResultSet { Results = data };

            BigInteger result = testSet.GetResult(5);
        }
        public void TestGetResult_Negative()
        {
            BigInteger[] data = { 0, 1, 2, 3 };
            FibonacciResultSet testSet = new FibonacciResultSet { Results = data };

            BigInteger result = testSet.GetResult(-1);
        }
Esempio n. 3
0
        public FibonacciResultSet Compute(int len)
        {
            if (len < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            var results = new BigInteger[len];

            // zero case
            if (len == 0)
            {
                return new FibonacciResultSet { Results = results };
            }

            // one case
            results[0] = 0;
            if (len == 1)
            {
                return new FibonacciResultSet { Results = results };
            }

            // compute values
            results[1] = 1;
            for (int i = 2; i < len; i++)
            {
                results[i] = results[i - 1] + results[i - 2];
            }

            FibonacciResultSet resultSet = new FibonacciResultSet { Results = results };

            return resultSet;
        }
        public void TestGetAllResults()
        {
            BigInteger[] data = { 0, 1, 2, 3 };
            FibonacciResultSet testSet = new FibonacciResultSet { Results = data };

            BigInteger[] allResults = testSet.GetAllResults();

            CollectionAssert.AreEqual(data, allResults);
        }
        public void TestGetResult_Valid()
        {
            BigInteger[] data = { 0, 1, 2, 3 };
            FibonacciResultSet testSet = new FibonacciResultSet { Results = data };

            BigInteger expected = 1;
            BigInteger actual = testSet.GetResult(1);

            Assert.AreEqual(expected, actual);
        }
        public void WriteResult(FibonacciResultSet resultSet)
        {
            BigInteger[] results = resultSet.GetAllResults();

            for (int i = 0; i < results.Length; i++)
            {
                Console.Write("{0} ", results[i]);
            }
            Console.WriteLine();
        }
 public void WriteResult(FibonacciResultSet results)
 {
     using (Stream stream = File.Create(_fileName))
     using (StreamWriter writer = new StreamWriter(stream))
     {
         for (int i = 0; i < results.GetAllResults().Length; i++)
         {
             writer.Write(string.Format("{0} ", results.GetAllResults()[i]));
         }
     }
 }
        private static XDocument ConstructXMLDoc(FibonacciResultSet results)
        {
            IEnumerable<BigInteger> enumList = results.GetAllResults();
            XDocument doc = new XDocument(
                new XElement("fiboutput",
                    enumList.Select(n => new XElement("result", n.ToString()))
                )
            );

            return doc;
        }
Esempio n. 9
0
        private static void HandleOutput(CliOptions options, FibonacciResultSet resultSet)
        {
            IFibonacciOutput outputMethod;

            if (options.OutputFile == null)
            {
                outputMethod = new DirectFibonacciOutput();
            }
            else if (Path.GetExtension(options.OutputFile) == ".xml")
            {
                outputMethod = new XMLFibonacciOutput(options.OutputFile);
            }
            else
            {
                outputMethod = new PlainTextFibonacciOutput(options.OutputFile);
            }

            outputMethod.WriteResult(resultSet);
        }
Esempio n. 10
0
 public void WriteResult(FibonacciResultSet results)
 {
     XDocument xmlDoc = ConstructXMLDoc(results);
     xmlDoc.Save(_fileName);
 }