Skip to content

Commit

Permalink
Merge pull request #525 from zyzhu/issue-445
Browse files Browse the repository at this point in the history
Add C# test cases of slicing rows and columns
  • Loading branch information
zyzhu authored Feb 20, 2021
2 parents bd77982 + 71e7594 commit c5c011a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
14 changes: 5 additions & 9 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
"isRoot": true,
"tools": {
"fake-cli": {
"version": "5.19.0",
"commands": [
"fake"
]
"version": "5.20.3",
"commands": ["fake"]
},
"paket": {
"version": "5.241.6",
"commands": [
"paket"
]
"version": "6.0.0-beta8",
"commands": ["paket"]
}
}
}
}
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.0.100",
"rollForward": "minor"
"rollForward": "major"
}
}
44 changes: 31 additions & 13 deletions tests/Deedle.CSharp.Tests/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

namespace Deedle.CSharp.Tests
{
/* ----------------------------------------------------------------------------------
* Test calling Frame.Zip from C#
* --------------------------------------------------------------------------------*/
public class FrameZipTests
{
public static Frame<int, string> LoadMSFT([CallerFilePath] string source = "")
{
var file = Path.Combine(Path.GetDirectoryName(source), "..", "Deedle.Tests", "data", "MSFT.csv");
return Frame.ReadCsv(file, inferRows:10);
}
public class Common
{
public static Frame<int, string> LoadMSFT([CallerFilePath] string source = "")
{
var file = Path.Combine(Path.GetDirectoryName(source), "..", "Deedle.Tests", "data", "MSFT.csv");
return Frame.ReadCsv(file, inferRows: 10);
}

public static Frame<int, string> LoadMSFTStream([CallerFilePath] string source = "")
{
Expand All @@ -27,19 +24,24 @@ public static Frame<int, string> LoadMSFTStream([CallerFilePath] string source =
sr.Close();
return csv;
}

}
/* ----------------------------------------------------------------------------------
* Test calling Frame.Zip from C#
* --------------------------------------------------------------------------------*/
public class FrameZipTests
{
[Test]
public static void CanSubtractNumericalValues()
{
var df = LoadMSFT();
var df = Common.LoadMSFT();
var actual = df.Zip<float, float, float>(df, (n1, n2) => n1 - n2).GetAllValues<float>().Sum();
Assert.AreEqual(0.0, actual);
}

[Test]
public static void CanSubtractNumericalValuesStream()
{
var df = LoadMSFTStream();
var df = Common.LoadMSFTStream();
var actual = df.Zip<float, float, float>(df, (n1, n2) => n1 - n2).GetAllValues<float>().Sum();
Assert.AreEqual(0.0, actual);
}
Expand Down Expand Up @@ -149,6 +151,22 @@ public static void DropSparseRowsFromRecords()
Assert.AreEqual(1.0, b[0].Value);
Assert.AreEqual(3.0, b[1].Value);
}

[Test]
public static void CanSliceRows()
{
var df = Common.LoadMSFT();
var actual = df.Rows[new int[] { 0, 1, 2, 3, 4 }];
Assert.AreEqual(5, actual.RowCount);
}

[Test]
public static void CanSliceCols()
{
var df = Common.LoadMSFT();
var actual = df.Columns[new string[] { "Open", "High" }];
Assert.AreEqual(2, actual.ColumnCount);
}
}

/* ----------------------------------------------------------------------------------
Expand Down

0 comments on commit c5c011a

Please sign in to comment.