Exemple #1
0
        private void GeoPositionExecuteTests(
            Tuple <float, float> geoCoordinates,                    // latitude, longitude
            List <DateTimeOffset> dateTimeInputList,
            List <Tuple <float, float> > expectedOutputsList,       // azimuth, elevation (uncorrected)
            float ERROR_RATE,
            bool testAzimuth)
        {
            Assert.IsTrue(dateTimeInputList.Count == expectedOutputsList.Count);
            for (int testCaseIndex = 0; testCaseIndex < dateTimeInputList.Count; ++testCaseIndex)
            {
                DateTimeOffset dt             = dateTimeInputList[testCaseIndex];
                var            expectedResult = expectedOutputsList[testCaseIndex];
                (float resultAzimuth, float resultAltitude) = SunStudy.CalculateSunPosition(dt, geoCoordinates.Item1, geoCoordinates.Item2);

                if (testAzimuth)
                {
                    Assert.AreEqual(expectedResult.Item1, resultAzimuth, ERROR_RATE, $"Azimuth not equal with {ERROR_RATE} acc.: TestH: {dt.Hour}");
                }
                else
                {
                    Assert.AreEqual(expectedResult.Item2, resultAltitude, ERROR_RATE, $"Elevation not equal with {ERROR_RATE} acc.: TestH: {dt.Hour}");
                }
            }
        }
        void ExecuteTest(float errorThreshold, string testJsonFileName, bool testAzimuth)
        {
            SunStudyTestJson.RootTest testData = LoadTestData(testJsonFileName);

            var geoCoordinates  = Tuple.Create <float, float>(testData.latitude, testData.longitude);
            int utcOffsetHour   = (int)testData.utcOffset;
            int utcOffsetMinute = (int)((testData.utcOffset - utcOffsetHour) * 60f);
            var offset          = new TimeSpan(utcOffsetHour, utcOffsetMinute, 0);

            var dateTimeInputs  = new List <DateTimeOffset>();
            var expectedOutputs = new List <Tuple <float, float> >();

            foreach (var test in testData.values)
            {
                dateTimeInputs.Add(new DateTimeOffset(test.dateY, test.dateM, test.dateD, test.timeH, test.timeM, test.timeS, offset));
                expectedOutputs.Add(Tuple.Create <float, float>(test.azimuth, test.elevation));
            }

            Assert.IsTrue(dateTimeInputs.Count == expectedOutputs.Count);

            for (int testCaseIndex = 0; testCaseIndex < dateTimeInputs.Count; ++testCaseIndex)
            {
                DateTimeOffset dateTime       = dateTimeInputs[testCaseIndex];
                var            expectedResult = expectedOutputs[testCaseIndex];
                (float resultAzimuth, float resultAltitude) = SunStudy.CalculateSunPosition(dateTime, geoCoordinates.Item1, geoCoordinates.Item2);

                if (testAzimuth)
                {
                    Assert.AreEqual(expectedResult.Item1, resultAzimuth, errorThreshold, $"Azimuth not equal with {errorThreshold} accuracy at Hour {dateTime.Hour}.");
                }
                else
                {
                    Assert.AreEqual(expectedResult.Item2, resultAltitude, errorThreshold, $"Elevation not equal with {errorThreshold} accuracy at Hour {dateTime.Hour}.");
                }
            }
        }