Skip to content

Commit

Permalink
Merge branch 'release/v2.8.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrenier committed Dec 15, 2019
2 parents 1930ecd + c0a25cc commit 8118f32
Show file tree
Hide file tree
Showing 13 changed files with 2,892 additions and 598 deletions.
1,606 changes: 1,076 additions & 530 deletions SwissEphNet/CPort/Sweph.cs

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions SwissEphNet/CPort/SwephLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3712,8 +3712,30 @@ public static int swi_cutstr(string s, char[] cutlist, out string[] cpos, int nm
//}
//if (n < nmax) cpos[n] = NULL;
//return (n);
cpos = s?.Split(cutlist, nmax, StringSplitOptions.RemoveEmptyEntries) ??
Enumerable.Range(0, nmax).Select(i => string.Empty).ToArray();

s = s ?? string.Empty;
int ps = 0, pe = s.Length;
List<string> result = new List<string>();
int p = ps;
while (p < pe)
{
char c = s[p];
if(cutlist.Contains(c) && result.Count < nmax)
{
result.Add(s.Substring(ps, p - ps));
while (p < pe && cutlist.Contains(s[p])) p++;
ps = p;
}
if (c == '\n' || c == '\r')
{
pe = p;
break;
}
p++;
}
if (ps < pe)
result.Add(s.Substring(ps, pe - ps));
cpos = result.ToArray();
return cpos.Length;
} /* cutstr */

Expand Down
4 changes: 2 additions & 2 deletions SwissEphNet/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
[assembly: GuidAttribute("067b4733-56fd-46a1-81b5-0fd31d76e68f")]
#endif

[assembly: AssemblyVersion("2.8.0.1")]
[assembly: AssemblyFileVersion("2.8.0.1")]
[assembly: AssemblyVersion("2.8.0.2")]
[assembly: AssemblyFileVersion("2.8.0.2")]
#endif
7 changes: 5 additions & 2 deletions SwissEphNet/SwissEphNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<RootNamespace>SwissEphNet</RootNamespace>
<PackageId>SwissEphNet</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.8.0.1</Version>
<Version>2.8.0.2</Version>
<Authors>Yan Grenier</Authors>
<Company>Yan Grenier</Company>
<Product>SwissEphNet</Product>
Expand All @@ -17,7 +17,10 @@
<RepositoryUrl>https://github.com/ygrenier/SwissEphNet</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Swiss Ephemeris</PackageTags>
<PackageReleaseNotes>2.8.0.1:
<PackageReleaseNotes>2.8.0.2:
- Fix the #41 issue

2.8.0.1:
- Update to version 2.08 of SwissEphemeris

2.7.1.3:
Expand Down
15 changes: 14 additions & 1 deletion SwissEphNet/Tools/C.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ public bcomparer(TKey key, Func<TKey, TVal, int> compare)
}
public int Compare(TVal x, TVal y)
{
return Comparer(Key, y);
bool xIsDefault = x == null || x.Equals(default(TVal));
bool yIsDefault = y == null || y.Equals(default(TVal));
if (yIsDefault && !xIsDefault)
{
int c = Comparer(Key, x);
if (c != 0) return -c;
return c;
}
else if (xIsDefault && !yIsDefault)
{
return Comparer(Key, y);
}
else
return -1;
}
public TKey Key { get; }
public Func<TKey, TVal, int> Comparer { get; }
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwissEphNet.Tests/Issue18Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void LoadAsteroidData()

// The issue raised a FormatException
swe.swe_calc_ut(tjd, SwissEph.SE_AST_OFFSET + 5, SwissEph.SEFLG_SWIEPH, xx, ref serr);
Assert.Equal(130.764380953383, xx[0], 12);
Assert.Equal(130.764380953383, xx[0], 11);
Assert.Equal(-1.0445487020471, xx[1], 13);
Assert.Equal(3.0793896379558, xx[2], 13);
Assert.Equal(0, xx[3], 13);
Expand Down
134 changes: 134 additions & 0 deletions Tests/SwissEphNet.Tests/Issue41Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace SwissEphNet.Tests
{
/// <summary>
/// Issue #41 : https://github.com/ygrenier/SwissEphNet/issues/41
/// </summary>
public class Issue41Test
{
public static IEnumerable<object[]> TestDataFixstar()
{
yield return new object[] { "1", 4, "Aldebaran,alTau", null };
yield return new object[] { "5", 4, "Regulus,alLeo", null };
yield return new object[] { "10", 4, "Gal. Center,SgrA*", null };
yield return new object[] { "25", 4, "Mirach,beAnd", null };
yield return new object[] { "1000", 4, "Samakah,bePsc", null };
yield return new object[] { "10000", -1, "", "star 10000 not found" };
yield return new object[] { "aldeb", 4, "Aldebaran,alTau", null };
yield return new object[] { ",alTau", 4, "Aldebaran,alTau", null };
yield return new object[] { "aldeb%", -1, "", "star aldeb% not found" };
yield return new object[] { "Spica", 4, "Spica,alVir", null };
yield return new object[] { "alVir", -1, "", "star alVir not found" };
yield return new object[] { ",alVir", 4, "Spica,alVir", null };
}

[Theory]
[MemberData(nameof(TestDataFixstar))]
public void TestFixstar(string search, int eres, string estar, string error)
{
int day = 16, month = 8, year = 1974;
double time = 0.05;

using (var swe = new SwissEph())
{
swe.OnLoadFile += (s, e) =>
{
string f = e.FileName;
string fn = Path.GetFileName(f);
if (File.Exists(f))
{
e.File = new FileStream(f, FileMode.Open, FileAccess.Read);
}
else
{
e.File = ResourceFileHelpers.OpenResourceFile(fn);
}
};

double[] xx = new double[6];

double tjd = swe.swe_julday(year, month, day, time, SwissEph.SE_GREG_CAL);
double te = tjd + swe.swe_deltat(tjd);

string star = search, serr = null;
int res = swe.swe_fixstar(ref star, te, SwissEph.SEFLG_MOSEPH, xx, ref serr);
Assert.Equal(eres, res);
if (res == SwissEph.ERR)
{
Assert.Equal(error, serr);
}
else
{
Assert.Equal(estar, star);
}
}
}

public static IEnumerable<object[]> TestDataFixstar2()
{
yield return new object[] { "1", 4, ",109Vir", null };
yield return new object[] { "5", 4, ",13Mon", null };
yield return new object[] { "10", 4, "Electra,17Tau", null };
yield return new object[] { "25", 4, ",26UMa", null };
yield return new object[] { "1000", 4, "Rukbalgethi Genubi,thHer", null };
yield return new object[] { "10000", -1, "", "error, swe_fixstar(): sequential fixed star number 10000 is not available" };
yield return new object[] { "aldebaran", 4, "Aldebaran,alTau", null };
yield return new object[] { "aldeb", -1, "", "error, swe_fixstar(): could not find star name aldeb" };
yield return new object[] { ",alTau", 4, "Aldebaran,alTau", null };
yield return new object[] { "aldeb%", 4, "Aldebaran,alTau", null };
yield return new object[] { "Spica", 4, "Spica,alVir", null };
yield return new object[] { "alVir", -1, "", "error, swe_fixstar(): could not find star name alvir" };
yield return new object[] { ",alVir", 4, "Spica,alVir", null };
}

[Theory]
[MemberData(nameof(TestDataFixstar2))]
public void TestFixstar2(string search, int eres, string estar, string error)
{
int day = 16, month = 8, year = 1974;
double time = 0.05;

using (var swe = new SwissEph())
{
swe.OnLoadFile += (s, e) =>
{
string f = e.FileName;
string fn = Path.GetFileName(f);
if (File.Exists(f))
{
e.File = new FileStream(f, FileMode.Open, FileAccess.Read);
}
else
{
e.File = ResourceFileHelpers.OpenResourceFile(fn);
}
};

double[] xx = new double[6];

double tjd = swe.swe_julday(year, month, day, time, SwissEph.SE_GREG_CAL);
double te = tjd + swe.swe_deltat(tjd);

string star = search, serr = null;
int res = swe.swe_fixstar2(ref star, te, SwissEph.SEFLG_MOSEPH, xx, ref serr);
Assert.Equal(eres, res);
if (res == SwissEph.ERR)
{
Assert.Equal(error, serr);
}
else
{
Assert.Equal(estar, star);
}
}
}

}
}
2 changes: 1 addition & 1 deletion Tests/SwissEphNet.Tests/StringExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class StringExtensionsTest
[Fact]
public void TestContainsChar() {
String s = null;
Assert.False(s.Contains('a'));
Assert.False(s?.Contains('a') ?? false);

Assert.False("".Contains('a'));
Assert.False("AbCd".Contains('a'));
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwissEphNet.Tests/SwissEphNet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netcoreapp1.0</TargetFrameworks>
<TargetFrameworks>net46;netcoreapp2.1</TargetFrameworks>
<AssemblyName>SwissEphNet.Tests</AssemblyName>
<PackageId>SwissEphNet.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.4</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">2.1.14</RuntimeFrameworkVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
Expand Down Expand Up @@ -44,7 +44,7 @@
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<DefineConstants>$(DefineConstants);NET_STANDARD</DefineConstants>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Tests/SwissEphNet.Tests/SwissEphTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void TestConstructor() {
public void TestVersion() {
using (var target = new SwissEph()) {
Assert.Equal("2.08", target.swe_version());
Assert.Equal("2.08.00-net-0001", target.swe_dotnet_version());
Assert.Equal("2.08.00-net-0002", target.swe_dotnet_version());
}
}

Expand Down
8 changes: 6 additions & 2 deletions Tests/SwissEphNet.Tests/SwissEphTest.swe_fixstar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public void Test_swe_fixstar()
Assert.Equal(0.01536112, xx[5], 8);
#endif

name = "test";
name = "unknown";
iflag = swe.swe_fixstar(ref name, tjd, SwissEph.SEFLG_MOSEPH, xx, ref serr);
Assert.Equal(SwissEph.ERR, iflag);
Assert.Equal("star test not found", serr);
Assert.Equal("star unknown not found", serr);
}
}

Expand Down Expand Up @@ -81,7 +81,11 @@ public void Test_swe_fixstar_ut()
Assert.Equal(0.000151, xx[3], 6);
Assert.Equal(1.7E-05, xx[4], 6);
#if DEBUG
#if NET_STANDARD
Assert.Equal(0.015543, xx[5], 6);
#else
Assert.Equal(0.015532, xx[5], 6);
#endif
#else
Assert.Equal(0.01536, xx[5], 6);
#endif
Expand Down
Loading

0 comments on commit 8118f32

Please sign in to comment.