-
Notifications
You must be signed in to change notification settings - Fork 2
/
BasicModelInterfaceLibraryTest.cs
151 lines (118 loc) · 3.86 KB
/
BasicModelInterfaceLibraryTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using NUnit.Framework;
namespace BasicModelInterface.Tests
{
[TestFixture]
public class BasicModelInterfaceLibraryTest
{
private const string LibraryC = @"..\..\..\..\bin\Debug\model-c.dll";
const string configFilePath = "empty";
private IBasicModelInterface library;
[SetUp]
public void SetUp()
{
library = new BasicModelInterfaceLibrary(LibraryC);
}
[Test]
public void InitializeAndFinish()
{
library.Initialize(configFilePath);
library.Finish();
}
[Test]
public void SingleTimeStep()
{
library.Initialize(configFilePath);
library.Update(-1);
library.Finish();
}
[Test]
public void StartTime()
{
Assert.AreEqual(new DateTime(), library.StartTime);
}
[Test]
public void StopTime()
{
Assert.AreEqual(new DateTime().AddSeconds(10), library.StopTime);
}
[Test]
public void TimeStep()
{
Assert.AreEqual(new TimeSpan(0, 0, 0, 1), library.TimeStep);
}
[Test]
public void CurrentTime()
{
Assert.AreEqual(new DateTime(), library.CurrentTime);
}
[Test]
public void InitializeTwoTimes()
{
library.Initialize(configFilePath);
library.Initialize(configFilePath);
}
[Test]
public void GetVariableNames()
{
Assert.AreEqual(3, library.VariableNames.Length);
Assert.AreEqual("arr1", library.VariableNames[0]);
Assert.AreEqual("arr2", library.VariableNames[1]);
Assert.AreEqual("arr3", library.VariableNames[2]);
}
[Test]
public void Run()
{
BasicModelInterfaceLibrary.Run(LibraryC, configFilePath);
}
[Test]
public void GetValues_1D_Double()
{
var values = library.GetValues(library.VariableNames[0]);
var valuesExpected = new[] { 3.0, 2.0, 1.0 };
Assert.AreEqual(valuesExpected, values);
}
[Test]
public void GetValues_2D_Int()
{
var values = library.GetValues(library.VariableNames[1]);
var valuesExpected = new[,] { { 3, 2, 1 }, { 6, 4, 2 } };
var v = 5.0;
library.SetValue("a", v);
Assert.AreEqual(valuesExpected, values);
}
[Test]
public void SetValues_1D_Double()
{
var values = new[] { 1.0, 2.0, 3.0 };
library.SetValues(library.VariableNames[0], values);
Assert.AreEqual(values, library.GetValues(library.VariableNames[0]));
}
[Test]
public void SetValues_2D_Int()
{
var values = new[,] { { 1, 2, 3 }, { 4, 5, 6 } };
library.SetValues(library.VariableNames[1], values);
library.SetValues(library.VariableNames[1], values);
Assert.AreEqual(values, library.GetValues(library.VariableNames[1]));
}
[Test]
public void SetValues_1D_Double_Slice()
{
var values = new[,] { { 1, 2, 3 } };
var start = new[] { 1, 0 };
var count = new[] { 1, 3 };
library.SetValues(library.VariableNames[1], start, count, values);
var valuesExpected = new[,] { { 3, 2, 1 }, { 1, 2, 3 } };
var valuesUpdated = library.GetValues(library.VariableNames[1]);
Assert.AreEqual(valuesExpected, valuesUpdated);
}
[Test]
public void SetLogger()
{
library.Logger = (level, message) => Console.WriteLine("{0}: {1}", level, message);
library.Initialize(string.Empty);
library.Finish();
}
}
}