Files
astronomy/generate/dotnet/csharp_test/csharp_test.cs
2019-10-25 16:00:52 -04:00

92 lines
3.1 KiB
C#

using System;
using System.IO;
using CosineKitty;
namespace csharp_test
{
class Program
{
static int Main(string[] args)
{
try
{
if (TestTime() != 0) return 1;
if (AstroCheck() != 0) return 1;
return 0;
}
catch (Exception ex)
{
Console.WriteLine("charp_test: EXCEPTION: {0}", ex);
return 1;
}
}
static int TestTime()
{
const int year = 2018;
const int month = 12;
const int day = 2;
const int hour = 18;
const int minute = 30;
const int second = 12;
const int milli = 543;
DateTime d = new DateTime(year, month, day, hour, minute, second, milli, DateTimeKind.Utc);
AstroTime time = new AstroTime(d);
Console.WriteLine("TestTime: text={0}, ut={1}, tt={2}", time.ToString(), time.ut.ToString("0.000000"), time.tt.ToString("0.000000"));
const double expected_ut = 6910.270978506945;
double diff = time.ut - expected_ut;
if (Math.Abs(diff) > 1.0e-12)
{
Console.WriteLine("TestTime: ERROR - excessive UT error {0}", diff);
return 1;
}
const double expected_tt = 6910.271779431480;
diff = time.tt - expected_tt;
if (Math.Abs(diff) > 1.0e-12)
{
Console.WriteLine("TestTime: ERROR - excessive TT error {0}", diff);
return 1;
}
DateTime utc = time.ToUtcDateTime();
if (utc.Year != year || utc.Month != month || utc.Day != day || utc.Hour != hour || utc.Minute != minute || utc.Second != second || utc.Millisecond != milli)
{
Console.WriteLine("TestTime: ERROR - Expected {0:o}, found {1:o}", d, utc);
return 1;
}
return 0;
}
static int AstroCheck()
{
const string filename = "csharp_check.txt";
using (StreamWriter outfile = File.CreateText(filename))
{
var bodylist = new Body[]
{
Body.Sun, Body.Mercury, Body.Venus, Body.Earth, Body.Mars,
Body.Jupiter, Body.Saturn, Body.Uranus, Body.Neptune, Body.Pluto
};
var observer = new Observer(29.0, -81.0, 10.0);
var time = new AstroTime(new DateTime(1700, 1, 1, 0, 0, 0, DateTimeKind.Utc));
var stop = new AstroTime(new DateTime(2200, 1, 1, 0, 0, 0, DateTimeKind.Utc));
while (time.tt < stop.tt)
{
foreach (Body body in bodylist)
{
AstroVector pos = Astronomy.HelioVector(body, time);
}
time = time.AddDays(10.0 + Math.PI/100.0);
}
}
return 0;
}
}
}