Exemplo n.º 1
0
        public void DoAssighment()
        {
            const string          InputLocation = "mockLocation";
            Dictionary <int, int> histDummy     = new Dictionary <int, int>
            {
                { 0, 3 },
                { 1, 1 }
            };

            double[] testSet        = new double[] { 3, 7, 7, 19 };
            var      dataLoaderMock = new Mock <IDataLoader>();

            dataLoaderMock.Setup(n => n.Load(InputLocation)).Returns(testSet);

            var statsServiceMock = new Mock <IStatsService>();

            statsServiceMock.Setup(n => n.CalcArithmeticMean(testSet)).Returns(9);
            statsServiceMock.Setup(n => n.CalcStandardDeviation(testSet)).Returns(6);
            statsServiceMock.Setup(n => n.GetHistogram(testSet)).Returns(histDummy);

            IAssignmentService service = new AssignmentService(dataLoaderMock.Object, statsServiceMock.Object);

            service.DoAssignment(InputLocation);

            dataLoaderMock.Verify(m => m.Load(InputLocation));
            statsServiceMock.Verify(n => n.CalcArithmeticMean(testSet));
            statsServiceMock.Verify(n => n.CalcStandardDeviation(testSet));
            statsServiceMock.Verify(n => n.GetHistogram(testSet));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                IDataLoader   dataLoader   = new CSVDataLoader(); //note, we dould implement different data loaders e.g. google sheets data loader.
                IStatsService statsService = new StatsService();

                //note for simplicity we are not using a service locator for example.
                IAssignmentService assignment = new AssignmentService(dataLoader, statsService);
                assignment.DoAssignment("SampleData.csv");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine("Invalid argument");
                Console.WriteLine(argEx.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("exceptions occured while running the program");
                Console.WriteLine(ex.ToString());
            }

            Console.ReadLine();
        }