-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
单元测试去掉net462,xunit对它的支持有些问题,导致测试结束时卡死
- Loading branch information
Showing
4 changed files
with
134 additions
and
139 deletions.
There are no files selected for viewing
212 changes: 105 additions & 107 deletions
212
XUnitTest.Core/Algorithms/AverageDownSamplingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,132 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using NewLife; | ||
using NewLife; | ||
using NewLife.Algorithms; | ||
using NewLife.Data; | ||
using NewLife.IO; | ||
using Xunit; | ||
|
||
namespace XUnitTest.Algorithms | ||
namespace XUnitTest.Algorithms; | ||
|
||
public class AverageDownSamplingTests | ||
{ | ||
public class AverageDownSamplingTests | ||
//[Fact] | ||
//public void DivTest() | ||
//{ | ||
// var n = 1234L; | ||
// var d1 = n / 3; | ||
// var d2 = n / 4; | ||
// Assert.Equal(411, d1); | ||
// Assert.Equal(308, d2); | ||
|
||
// Assert.Equal(411, (n + 1) / 3); | ||
// Assert.Equal(412, (n + 2) / 3); | ||
//} | ||
|
||
[Fact] | ||
public void Normal500() | ||
{ | ||
//[Fact] | ||
//public void DivTest() | ||
//{ | ||
// var n = 1234L; | ||
// var d1 = n / 3; | ||
// var d2 = n / 4; | ||
// Assert.Equal(411, d1); | ||
// Assert.Equal(308, d2); | ||
|
||
// Assert.Equal(411, (n + 1) / 3); | ||
// Assert.Equal(412, (n + 2) / 3); | ||
//} | ||
|
||
[Fact] | ||
public void Normal500() | ||
{ | ||
var data = ReadPoints(); | ||
var data = ReadPoints(); | ||
|
||
var sample = new AverageSampling(); | ||
var rs = sample.Down(data, 500); | ||
Assert.NotNull(rs); | ||
Assert.Equal(500, rs.Length); | ||
var sample = new AverageSampling(); | ||
var rs = sample.Down(data, 500); | ||
Assert.NotNull(rs); | ||
Assert.Equal(500, rs.Length); | ||
|
||
//var k = 0; | ||
//using var csv2 = new CsvFile("Algorithms/rs.csv"); | ||
//while (true) | ||
//{ | ||
// var line = csv2.ReadLine(); | ||
// if (line == null) break; | ||
//var k = 0; | ||
//using var csv2 = new CsvFile("Algorithms/rs.csv"); | ||
//while (true) | ||
//{ | ||
// var line = csv2.ReadLine(); | ||
// if (line == null) break; | ||
|
||
// Assert.Equal(line[0].ToInt(), rs[k].Time); | ||
// Assert.True(Math.Abs(line[1].ToDouble() - rs[k].Value) < 0.0001); | ||
// Assert.Equal(line[0].ToInt(), rs[k].Time); | ||
// Assert.True(Math.Abs(line[1].ToDouble() - rs[k].Value) < 0.0001); | ||
|
||
// k++; | ||
//} | ||
// k++; | ||
//} | ||
|
||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
|
||
private TimePoint[] ReadPoints(String fileName = "source.csv") | ||
private TimePoint[] ReadPoints(String fileName = "source.csv") | ||
{ | ||
using var csv = new CsvFile($"Algorithms/{fileName}"); | ||
var data = new List<TimePoint>(); | ||
while (true) | ||
{ | ||
using var csv = new CsvFile($"Algorithms/{fileName}"); | ||
var data = new List<TimePoint>(); | ||
while (true) | ||
{ | ||
var line = csv.ReadLine(); | ||
if (line == null) break; | ||
|
||
data.Add(new TimePoint { Time = line[0].ToLong(), Value = line[1].ToDouble() }); | ||
} | ||
return data.ToArray(); | ||
var line = csv.ReadLine(); | ||
if (line == null) break; | ||
|
||
data.Add(new TimePoint { Time = line[0].ToLong(), Value = line[1].ToDouble() }); | ||
} | ||
return data.ToArray(); | ||
} | ||
|
||
private void WritePoints(ISampling sample, TimePoint[] data, AlignModes mode, String prefix = null) | ||
private void WritePoints(ISampling sample, TimePoint[] data, AlignModes mode, String prefix = null) | ||
{ | ||
if (prefix.IsNullOrEmpty()) prefix = "avg"; | ||
//var f = $"Algorithms/{prefix}_{mode}_sampled.csv".GetFullPath(); | ||
////if (sample.BucketSize > 0) f = $"Algorithms/avgfill_{mode}_sampled.csv".GetFullPath(); | ||
//if (File.Exists(f)) File.Delete(f); | ||
//using var csv = new CsvFile(f, true); | ||
var ms = new MemoryStream(); | ||
using var csv = new CsvFile(ms, true); | ||
for (var i = 0; i < data.Length; i++) | ||
{ | ||
if (prefix.IsNullOrEmpty()) prefix = "avg"; | ||
var f = $"Algorithms/{prefix}_{mode}_sampled.csv".GetFullPath(); | ||
//if (sample.BucketSize > 0) f = $"Algorithms/avgfill_{mode}_sampled.csv".GetFullPath(); | ||
if (File.Exists(f)) File.Delete(f); | ||
using var csv = new CsvFile(f, true); | ||
for (var i = 0; i < data.Length; i++) | ||
{ | ||
csv.WriteLine(data[i].Time, data[i].Value); | ||
} | ||
csv.Dispose(); | ||
|
||
//XTrace.WriteLine(f); | ||
csv.WriteLine(data[i].Time, data[i].Value); | ||
} | ||
csv.Dispose(); | ||
|
||
[Fact] | ||
public void AlignLeftTest() | ||
{ | ||
var data = ReadPoints(); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Left }; | ||
var rs = sample.Down(data, 100); | ||
Assert.NotNull(rs); | ||
Assert.Equal(100, rs.Length); | ||
//XTrace.WriteLine(f); | ||
} | ||
|
||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
[Fact] | ||
public void AlignLeftTest() | ||
{ | ||
var data = ReadPoints(); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Left }; | ||
var rs = sample.Down(data, 100); | ||
Assert.NotNull(rs); | ||
Assert.Equal(100, rs.Length); | ||
|
||
[Fact] | ||
public void AlignRightTest() | ||
{ | ||
var data = ReadPoints(); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Right }; | ||
var rs = sample.Down(data, 500); | ||
Assert.NotNull(rs); | ||
Assert.Equal(500, rs.Length); | ||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
|
||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
[Fact] | ||
public void AlignRightTest() | ||
{ | ||
var data = ReadPoints(); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Right }; | ||
var rs = sample.Down(data, 500); | ||
Assert.NotNull(rs); | ||
Assert.Equal(500, rs.Length); | ||
|
||
[Fact] | ||
public void AlignCenterTest() | ||
{ | ||
var data = ReadPoints(); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Center }; | ||
var rs = sample.Down(data, 500); | ||
Assert.NotNull(rs); | ||
Assert.Equal(500, rs.Length); | ||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
|
||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
[Fact] | ||
public void AlignCenterTest() | ||
{ | ||
var data = ReadPoints(); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Center }; | ||
var rs = sample.Down(data, 500); | ||
Assert.NotNull(rs); | ||
Assert.Equal(500, rs.Length); | ||
|
||
[Fact] | ||
public void Fill500() | ||
{ | ||
var data = ReadPoints("source2.csv"); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Left }; | ||
var rs = sample.Process(data, 60, 5); | ||
Assert.NotNull(rs); | ||
Assert.Equal(126, rs.Length); | ||
//Assert.Equal(5, rs[0].Time); | ||
//Assert.Equal(65, rs[1].Time); | ||
//Assert.Equal(125, rs[2].Time); | ||
|
||
WritePoints(sample, rs, sample.AlignMode, "avgfill"); | ||
} | ||
WritePoints(sample, rs, sample.AlignMode); | ||
} | ||
|
||
[Fact] | ||
public void Fill500() | ||
{ | ||
var data = ReadPoints("source2.csv"); | ||
var sample = new AverageSampling { AlignMode = AlignModes.Left }; | ||
var rs = sample.Process(data, 60, 5); | ||
Assert.NotNull(rs); | ||
Assert.Equal(126, rs.Length); | ||
//Assert.Equal(5, rs[0].Time); | ||
//Assert.Equal(65, rs[1].Time); | ||
//Assert.Equal(125, rs[2].Time); | ||
|
||
WritePoints(sample, rs, sample.AlignMode, "avgfill"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using NewLife.Log; | ||
using NewLife.Log; | ||
using Xunit; | ||
|
||
namespace XUnitTest.Log | ||
namespace XUnitTest.Log; | ||
|
||
public class NetworkLogTests | ||
{ | ||
public class NetworkLogTests | ||
[Fact] | ||
public void UdpLog() | ||
{ | ||
[Fact] | ||
public void UdpLog() | ||
{ | ||
using var netLog = new NetworkLog(); | ||
netLog.Write(LogLevel.Info, "This is {0}", Environment.MachineName); | ||
netLog.Write(LogLevel.Info, "I am {0}", Environment.UserName); | ||
} | ||
using var netLog = new NetworkLog(); | ||
netLog.Write(LogLevel.Info, "This is {0}", Environment.MachineName); | ||
netLog.Write(LogLevel.Info, "I am {0}", Environment.UserName); | ||
} | ||
|
||
[Fact] | ||
public void TcpLog() | ||
{ | ||
using var netLog = new NetworkLog("tcp://127.0.0.1:514"); | ||
netLog.Write(LogLevel.Info, "This is {0}", Environment.MachineName); | ||
netLog.Write(LogLevel.Info, "I am {0}", Environment.UserName); | ||
} | ||
[Fact] | ||
public void TcpLog() | ||
{ | ||
using var netLog = new NetworkLog("tcp://127.0.0.1:514"); | ||
netLog.Write(LogLevel.Info, "This is {0}", Environment.MachineName); | ||
netLog.Write(LogLevel.Info, "I am {0}", Environment.UserName); | ||
} | ||
|
||
[Fact] | ||
public void HttpLog() | ||
{ | ||
using var netLog = new NetworkLog("http://baidu.com/log"); | ||
netLog.Write(LogLevel.Info, "This is {0}", Environment.MachineName); | ||
netLog.Write(LogLevel.Info, "I am {0}", Environment.UserName); | ||
[Fact] | ||
public void HttpLog() | ||
{ | ||
using var netLog = new NetworkLog("http://baidu.com/log"); | ||
netLog.Write(LogLevel.Info, "This is {0}", Environment.MachineName); | ||
netLog.Write(LogLevel.Info, "I am {0}", Environment.UserName); | ||
|
||
for (var i = 0; i < 10; i++) | ||
{ | ||
netLog.Write(LogLevel.Info, "Hello +" + i); | ||
} | ||
for (var i = 0; i < 10; i++) | ||
{ | ||
netLog.Write(LogLevel.Info, "Hello +" + i); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters