Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
sparrowzz
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
sgool
sparrowzz
Commits
45eed44f
Commit
45eed44f
authored
Jul 15, 2024
by
dongshufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove tests
parent
e6bcba7b
全部展开
显示空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
4 行增加
和
1090 行删除
+4
-1090
eig-aoe/src/aoe/mod.rs
+0
-0
eig-aoe/src/lib.rs
+0
-0
eig-aoe/src/solvers/mod.rs
+0
-132
eig-aoe/src/solvers/utils.rs
+4
-4
eig-domain/src/dlt645.rs
+0
-184
eig-domain/src/ethercat.rs
+0
-15
eig-domain/src/excel.rs
+0
-157
eig-domain/src/hymqtt.rs
+0
-134
eig-domain/src/iec104.rs
+0
-87
eig-domain/src/lib.rs
+0
-234
eig-domain/src/memory.rs
+0
-26
eig-domain/src/modbus.rs
+0
-0
eig-domain/src/mqtt.rs
+0
-117
没有找到文件。
eig-aoe/src/aoe/mod.rs
查看文件 @
45eed44f
差异被折叠。
点击展开。
eig-aoe/src/lib.rs
查看文件 @
45eed44f
差异被折叠。
点击展开。
eig-aoe/src/solvers/mod.rs
查看文件 @
45eed44f
...
...
@@ -9,135 +9,3 @@ pub use utils::*;
pub
mod
model
;
pub
mod
utils
;
\ No newline at end of file
#[allow(non_snake_case)]
#[cfg(test)]
mod
tests
{
use
std
::
f64
::
consts
::
PI
;
use
std
::
ops
::
Mul
;
use
approx
::
assert_relative_eq
;
use
ndarray
::
array
;
use
num
::
pow
::
Pow
;
use
num_complex
::{
Complex64
,
ComplexFloat
};
//noinspection ALL
#[test]
fn
test_2_1
()
{
let
GMRabc
=
0.00744
;
let
_GMRn
=
0.00248
;
let
rabc
=
0.190
;
let
_rn
=
0.368
;
let
Dab
=
0.7622
;
let
_Dbc
=
1.3720
;
let
_Dca
=
2.1342
;
let
_Dan
=
1.7247
;
let
_Dbn
=
1.3025
;
let
_Dcn
=
1.5244
;
let
zaa
=
Complex64
::
new
(
rabc
+
0.0493
,
0.0628
*
((
1.0
/
GMRabc
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
zaa
.re
,
0.2393
,
max_relative
=
1e-4
);
assert_relative_eq!
(
zaa
.im
,
0.8118
,
max_relative
=
1e-4
);
// let zaa = Complex64::new(0.2393, 0.8118);
let
zab
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
Dab
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
zab
.im
,
0.5210
,
max_relative
=
1e-4
);
// let zab = Complex64::new(0.0493, 0.5210);
let
zac
=
Complex64
::
new
(
0.0493
,
0.4564
);
let
zan
=
Complex64
::
new
(
0.0493
,
0.4698
);
let
zbc
=
Complex64
::
new
(
0.0493
,
0.4841
);
let
zbn
=
Complex64
::
new
(
0.0493
,
0.4874
);
let
zcn
=
Complex64
::
new
(
0.0493
,
0.4775
);
let
znn
=
array!
[
Complex64
::
new
(
0.4173
,
0.8807
)];
let
zij
=
array!
[[
zaa
,
zab
,
zac
],
[
zab
,
zaa
,
zbc
],
[
zac
,
zbc
,
zaa
]];
let
zin
=
array!
[[
zan
],
[
zbn
],
[
zcn
]];
let
znj
=
array!
[
zan
,
zbn
,
zcn
];
let
zabc
=
zij
-
zin
.mul
(
array!
[
Complex64
::
new
(
1.0
,
0.0
)]
/
znn
)
.mul
(
znj
);
println!
(
"{:?}"
,
zabc
);
let
a
=
Complex64
::
new
(
f64
::
cos
(
2.0
*
PI
/
3.0
),
f64
::
sin
(
2.0
*
PI
/
3.0
));
println!
(
"as: {:?}"
,
a
);
let
matrix_as
=
array!
[
[
Complex64
::
new
(
1.0
,
0.0
),
Complex64
::
new
(
1.0
,
0.0
),
Complex64
::
new
(
1.0
,
0.0
)
],
[
Complex64
::
new
(
1.0
,
0.0
),
a
*
a
,
a
],
[
Complex64
::
new
(
1.0
,
0.0
),
a
,
a
*
a
]
];
println!
(
"As: {:?}"
,
matrix_as
);
let
matrix_as_inv
=
array!
[
[
Complex64
::
new
(
1.0
/
3.0
,
0.0
),
Complex64
::
new
(
1.0
/
3.0
,
0.0
),
Complex64
::
new
(
1.0
/
3.0
,
0.0
)
],
[
Complex64
::
new
(
1.0
/
3.0
,
0.0
),
a
*
Complex64
::
new
(
1.0
/
3.0
,
0.0
),
a
*
a
*
Complex64
::
new
(
1.0
/
3.0
,
0.0
)
],
[
Complex64
::
new
(
1.0
/
3.0
,
0.0
),
a
*
a
*
Complex64
::
new
(
1.0
/
3.0
,
0.0
),
a
*
Complex64
::
new
(
1.0
/
3.0
,
0.0
)
]
];
println!
(
"As_inv {:?}"
,
matrix_as_inv
);
println!
(
"As_inv * As: {:?}"
,
matrix_as_inv
.dot
(
&
matrix_as
));
let
temp
=
matrix_as_inv
.dot
(
&
zabc
);
let
z012
=
temp
.dot
(
&
matrix_as
);
// let z012 = As_inv * zabc * As;
assert_relative_eq!
(
z012
.get
([
0
,
0
])
.unwrap
()
.re
(),
0.5050
,
max_relative
=
1e-4
);
}
//noinspection ALL
#[test]
#[allow(non_snake_case)]
fn
test_2_2
()
{
let
GMRc
=
0.005212
;
let
GMRs
=
0.000634
;
let
dod
=
3.2766
;
let
_dc
=
1.4402
;
let
rc
=
0.2548
;
let
ds
=
0.162814
;
let
rs
=
9.2411
;
let
k
=
13.0
;
let
R
=
(
dod
-
ds
)
/
200
.
;
assert_relative_eq!
(
R
,
0.01557
,
max_relative
=
1e-4
);
let
tmp
:
f64
=
GMRs
*
k
*
R
.pow
(
k
-
1.0
);
let
GMRcn
=
tmp
.pow
(
1.0
/
k
);
assert_relative_eq!
(
GMRcn
,
0.01483
,
max_relative
=
1e-3
);
let
rcn
=
rs
/
k
;
let
D12
=
0.1524
;
let
D45
=
0.1524
;
let
_D23
=
0.1524
;
let
_D56
=
0.1524
;
let
D13
=
0.3048
;
let
D46
=
0.3048
;
let
D14
=
0.01557
;
let
_D25
=
0.01557
;
let
_D36
=
0.01557
;
let
D15
=
0.1524
;
let
_D26
=
0.1524
;
let
D16
=
0.3048
;
let
z11
=
Complex64
::
new
(
rc
+
0.0493
,
0.0628
*
((
1.0
/
GMRc
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z11
.re
,
0.3041
,
max_relative
=
1e-4
);
assert_relative_eq!
(
z11
.im
,
0.8341
,
max_relative
=
1e-4
);
let
z12
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
D12
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z12
.im
,
0.6221
,
max_relative
=
1e-4
);
let
z13
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
D13
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z13
.im
,
0.5786
,
max_relative
=
1e-4
);
let
z14
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
D14
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z14
.im
,
0.7654
,
max_relative
=
1e-4
);
let
z15
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
D15
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z15
.im
,
0.6221
,
max_relative
=
1e-4
);
let
z16
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
D16
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z16
.im
,
0.5786
,
max_relative
=
1e-4
);
let
z44
=
Complex64
::
new
(
rcn
+
0.0493
,
0.0628
*
((
1.0
/
GMRcn
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z44
.re
,
0.7602
,
max_relative
=
1e-4
);
assert_relative_eq!
(
z44
.im
,
0.7684
,
max_relative
=
1e-4
);
let
z45
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
D45
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z45
.im
,
0.6221
,
max_relative
=
1e-4
);
let
z46
=
Complex64
::
new
(
0.0493
,
0.0628
*
((
1.0
/
D46
)
.ln
()
+
8.02517
));
assert_relative_eq!
(
z46
.im
,
0.5786
,
max_relative
=
1e-4
);
}
}
eig-aoe/src/solvers/utils.rs
查看文件 @
45eed44f
...
...
@@ -961,7 +961,7 @@ mod tests {
r
.unwrap
()
);
let
expr
:
Expr
=
"6-x1+ x2/
2!
"
.parse
()
.unwrap
();
let
expr
:
Expr
=
"6-x1+ x2/
!2
"
.parse
()
.unwrap
();
let
r
=
split_linear_expr
(
expr
.rpn
,
&
x_pos
);
assert_eq!
(
vec!
[
...
...
@@ -972,7 +972,7 @@ mod tests {
r
.unwrap
()
);
let
expr
:
Expr
=
"6-x1+ x2/
var1!
"
.parse
()
.unwrap
();
let
expr
:
Expr
=
"6-x1+ x2/
!var1
"
.parse
()
.unwrap
();
let
r
=
split_linear_expr
(
expr
.rpn
,
&
x_pos
);
assert_eq!
(
vec!
[
...
...
@@ -991,7 +991,7 @@ mod tests {
r
.unwrap
()
);
let
expr
:
Expr
=
"-6-x1-(5>=4)*3*x2/
var1!
"
.parse
()
.unwrap
();
let
expr
:
Expr
=
"-6-x1-(5>=4)*3*x2/
!var1
"
.parse
()
.unwrap
();
let
r
=
split_linear_expr
(
expr
.rpn
,
&
x_pos
);
assert_eq!
(
vec!
[
...
...
@@ -1012,7 +1012,7 @@ mod tests {
r
.unwrap
()
);
let
expr
:
Expr
=
"-6-x1-((5>=4)*3*x2/
2!
+ (4<=1))*4"
.parse
()
.unwrap
();
let
expr
:
Expr
=
"-6-x1-((5>=4)*3*x2/
!2
+ (4<=1))*4"
.parse
()
.unwrap
();
let
r
=
split_linear_expr
(
expr
.rpn
,
&
x_pos
);
assert_eq!
(
vec!
[
...
...
eig-domain/src/dlt645.rs
查看文件 @
45eed44f
...
...
@@ -592,187 +592,3 @@ impl RegisterData {
})
}
}
\ No newline at end of file
#[cfg(test)]
mod
tests
{
use
std
::
collections
::
HashMap
;
use
crate
::
dlt645
::{
Dlt645ClientTp
,
Dlt645Para
};
use
crate
::{
SerialPara
,
SerialParity
};
use
crate
::
env
::
Env
;
#[test]
fn
test_parse_dlt_csv
()
{
Env
::
init
(
""
);
Env
::
set_vitrual_env
();
let
tp
=
Dlt645ClientTp
::
from_csv
(
"tests/dlt645-test1.csv"
)
.unwrap
();
assert_eq!
(
tp
.name
,
"DLT测试通道"
);
assert_eq!
(
tp
.connections
.len
(),
2
);
assert_eq!
(
tp
.para
,
Dlt645Para
::
Serial
(
SerialPara
{
file_path
:
"/dev/ttyUSB0"
.to_string
(),
baud_rate
:
19200
,
data_bits
:
10
,
stop_bits
:
2
,
parity
:
SerialParity
::
Odd
,
delay_between_requests
:
20
,
})
);
let
connection
=
tp
.connections
.first
()
.unwrap
();
assert_eq!
(
connection
.name
,
"测试通道1"
);
assert_eq!
(
connection
.slave_id
,
0x00
_00_00_34_03_10_98_67
);
assert_eq!
(
connection
.default_polling_period_in_milli
,
5000
);
assert_eq!
(
connection
.timeout_in_milli
,
1000
);
assert_eq!
(
connection
.polling_period_to_data
.len
(),
1
);
assert_eq!
(
connection
.polling_period_to_data
.get
(
&
5000u64
)
.unwrap
()
.len
(),
10
);
assert_eq!
(
connection
.data_configure
.len
(),
10
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.data_id
,
0x00
_00_00_00
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.point_ids
.len
(),
1
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.point_ids
[
0
],
4001
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.polling_period_in_milli
,
5000
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.data_id
,
0x01
_01_00_00
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.point_ids
.len
(),
2
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.point_ids
[
0
],
4007
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.point_ids
[
1
],
4011
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.polling_period_in_milli
,
5000
);
assert_eq!
(
connection
.data_configure
.get
(
9
)
.unwrap
()
.point_ids
[
0
],
4010
);
assert_eq!
(
connection
.data_configure
.get
(
9
)
.unwrap
()
.data_id
,
0x02
_80_00_0A
);
assert_eq!
(
connection
.data_configure
.get
(
9
)
.unwrap
()
.polling_period_in_milli
,
5000
);
let
connection
=
tp
.connections
.get
(
1
)
.unwrap
();
assert_eq!
(
connection
.name
,
"测试通道2"
);
assert_eq!
(
connection
.data_configure
.len
(),
20
);
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
Dlt645ClientTp
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
}
#[test]
fn
test_parse_dlt_csv2
()
{
let
tp
=
Dlt645ClientTp
::
from_csv
(
"tests/dlt645-test2.csv"
)
.unwrap
();
assert_eq!
(
tp
.name
,
"DLT测试通道"
);
assert_eq!
(
tp
.connections
.len
(),
2
);
assert_eq!
(
tp
.para
,
Dlt645Para
::
Socket
(
"127.0.0.1"
.to_string
(),
2300
));
let
connection
=
tp
.connections
.first
()
.unwrap
();
assert_eq!
(
connection
.name
,
"测试通道1"
);
assert_eq!
(
connection
.slave_id
,
0x00
_00_00_34_03_10_98_67
);
assert_eq!
(
connection
.default_polling_period_in_milli
,
5000
);
assert_eq!
(
connection
.timeout_in_milli
,
1000
);
assert_eq!
(
connection
.polling_period_to_data
.len
(),
1
);
assert_eq!
(
connection
.polling_period_to_data
.get
(
&
5000u64
)
.unwrap
()
.len
(),
10
);
assert_eq!
(
connection
.data_configure
.len
(),
10
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.data_id
,
0x00
_00_00_00
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.point_ids
.len
(),
1
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.point_ids
[
0
],
4001
);
assert_eq!
(
connection
.data_configure
.first
()
.unwrap
()
.polling_period_in_milli
,
5000
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.data_id
,
0x01
_01_00_00
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.point_ids
.len
(),
2
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.point_ids
[
0
],
4007
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.point_ids
[
1
],
4011
);
assert_eq!
(
connection
.data_configure
.get
(
6
)
.unwrap
()
.polling_period_in_milli
,
5000
);
assert_eq!
(
connection
.data_configure
.get
(
9
)
.unwrap
()
.point_ids
[
0
],
4010
);
assert_eq!
(
connection
.data_configure
.get
(
9
)
.unwrap
()
.data_id
,
0x02
_80_00_0A
);
assert_eq!
(
connection
.data_configure
.get
(
9
)
.unwrap
()
.polling_period_in_milli
,
5000
);
let
connection
=
tp
.connections
.get
(
1
)
.unwrap
();
assert_eq!
(
connection
.name
,
"测试通道2"
);
assert_eq!
(
connection
.data_configure
.len
(),
20
);
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
Dlt645ClientTp
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
}
// #[test]
// fn test_export_dlt_model() {
// let tp1 = Dlt645ClientTp::from_csv("tests/dlt645-test1.csv").unwrap();
// let tp1_export = tp1.export_model();
// let tp1_parse_from_export = Dlt645ClientTp::from_csv_bytes(tp1_export.as_bytes());
// assert_eq!(tp1_parse_from_export, Ok(tp1));
// let tp2 = Dlt645ClientTp::from_csv("tests/dlt645-test2.csv").unwrap();
// let tp2_export = tp2.export_model();
// let tp2_parse_from_export = Dlt645ClientTp::from_csv_bytes(tp2_export.as_bytes());
// assert_eq!(tp2_parse_from_export, Ok(tp2));
// }
}
eig-domain/src/ethercat.rs
查看文件 @
45eed44f
...
...
@@ -502,17 +502,3 @@ impl PdiData {
})
}
}
\ No newline at end of file
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
parse_file
()
{
let
file
=
"tests/ethercat-transport-test1.csv"
;
let
tp
=
EcMasterTp
::
from_file
(
file
);
assert
!
(
tp
.is_ok
());
let
tp
=
tp
.unwrap
();
assert_eq!
(
"enp5s0"
,
tp
.eth
);
}
}
\ No newline at end of file
eig-domain/src/excel.rs
查看文件 @
45eed44f
...
...
@@ -205,160 +205,4 @@ fn get_encoding(data: &[u8]) -> FileEncode {
}
}
return FileEncode::UTF8;
}
#[cfg(test)]
mod tests {
use std::io::{Cursor, Read, Write};
use super::*;
#[test]
fn test_parse() {
let bytes = std::fs::read("
..
/
eig
-
domain
/
tests
/
points
-
test1
.xlsx
").unwrap();
let mut c = Cursor::new(Vec::new());
c.write_all(bytes.as_slice()).unwrap();
let mut xl = open_workbook_auto_from_rs(c).unwrap();
let names = xl.sheet_names().to_owned();
let bytes = sheets_to_csv(&mut xl, names).unwrap()[0].clone();
let mut buf = String::new();
bytes.as_slice().read_to_string(&mut buf).unwrap();
println!("
{}
", buf);
}
#[test]
fn test_parse_points() {
use crate::{from_csv, from_csv_bytes2};
let path1 = "
tests
/
points
-
test1
.xlsx
";
let path2 = "
tests
/
points
-
test1
.csv
";
let bytes = excel_to_csv_bytes(path1).unwrap()[0].clone();
let (map1, tags1) = from_csv_bytes2(bytes.as_slice(), true, false).unwrap();
let (map2, tags2) = from_csv(path2).unwrap();
for key in map2.keys() {
assert_eq!(map1.get(key), map2.get(key));
}
assert_eq!(tags1, tags2);
}
#[test]
fn test_parse_points2() {
use crate::{from_csv, from_csv_bytes2};
let path1 = "
tests
/
points
-
test1
.csv
";
let path2 = "
tests
/
points
-
test1
.csv
";
let bytes = excel_to_csv_bytes(path1).unwrap()[0].clone();
let (map1, tags1) = from_csv_bytes2(bytes.as_slice(), true, false).unwrap();
let (map2, tags2) = from_csv(path2).unwrap();
for key in map2.keys() {
assert_eq!(map1.get(key), map2.get(key));
}
assert_eq!(tags1, tags2);
}
// #[test]
// fn test_parse_aoes() {
// use eig_aoe::aoe::parse::{from_csv_bytes, from_file};
// let path = "
..
/
eig
-
aoe
/
tests
/
test_zq
/
aoe
-
test1
.xlsx
";
// let path2 = "
..
/
eig
-
aoe
/
tests
/
test_zq
/
aoe
-
test1
.csv
";
// let bytes = excel_to_csv_bytes(path).unwrap()[0].clone();
// let aoes1 = from_csv_bytes(bytes.as_slice()).unwrap();
// let aoes2 = from_file(path2).unwrap();
// assert_eq!(3, aoes2.len());
// for i in 0..aoes2.len() {
// assert_eq!(aoes1[i].model, aoes2[i].model);
// }
// }
#[test]
fn test_parse_mbtcps() {
use crate::modbus::ModbusTcpClientTp;
let path = "
tests
/
tcp
-
mbc
-
test1
.xlsx
";
let path2 = "
tests
/
tcp
-
mbc
-
test1
.csv
";
let bytes = excel_to_csv_bytes(path).unwrap()[0].clone();
let mut buf = String::new();
bytes.as_slice().read_to_string(&mut buf).unwrap();
println!("
{}
", buf);
let tps1 = ModbusTcpClientTp::from_csv_bytes2(bytes.as_slice()).unwrap();
let tps2 = ModbusTcpClientTp::from_csv2(path2).unwrap();
assert_eq!(tps1, tps2);
}
#[test]
fn test_parse_kanban() {
let xlsx_bytes = std::fs::read("
tests
/
kanban1
.xlsx
").unwrap();
let (m, n, merged_cells) = get_first_sheet_merged_cells(xlsx_bytes).unwrap();
assert_eq!(m, 6);
assert_eq!(n, 12);
let mut is_dealt = vec![false; (m * n) as usize];
let mut cells = Vec::new();
for i in 0..m {
for j in 0..n {
let index = (i * n + j) as usize;
if is_dealt[index] {
continue;
}
let mut class_str = "
cell
".to_string();
let coordinate = (i, j);
if let Some((end_row, end_col)) = merged_cells.get(&coordinate) {
let row_span = *end_row - i + 1;
let col_span = *end_col - j + 1;
if row_span > 1 {
class_str.push_str(&format!("
is
-
row
-
span
-
{
row_span
}
"))
}
if col_span > 1 {
class_str.push_str(&format!("
is
-
col
-
span
-
{
col_span
}
"))
}
cells.push(class_str);
for row in i..=*end_row {
for col in j..=*end_col {
let pos = (row * n + col) as usize;
is_dealt[pos] = true;
}
}
} else {
cells.push(class_str);
}
}
}
assert_eq!(23, cells.len());
}
#[test]
fn test_parse_kanban2() {
let xlsx_bytes = std::fs::read("
tests
/
kanban2
.xlsx
").unwrap();
let (m, n, _) = get_first_sheet_merged_cells(xlsx_bytes).unwrap();
assert_eq!(m, 7);
assert_eq!(n, 12);
let xlsx_bytes = std::fs::read("
tests
/
kanban3
.xlsx
").unwrap();
let (m, n, _) = get_first_sheet_merged_cells(xlsx_bytes).unwrap();
assert_eq!(m, 7);
assert_eq!(n, 12);
}
#[test]
fn test_parse_file() {
let content = std::fs::read("
tests
/
GBK
.txt
").unwrap();
let encoding = get_encoding(content.as_slice());
assert_eq!(encoding, FileEncode::GBK);
let gbk = transfer_to_utf8(content).unwrap();
let content = std::fs::read("
tests
/
UTF8
.txt
").unwrap();
let encoding = get_encoding(content.as_slice());
assert_eq!(encoding, FileEncode::UTF8);
let utf8 = transfer_to_utf8(content).unwrap();
assert_eq!(gbk, utf8);
}
}
\ No newline at end of file
eig-domain/src/hymqtt.rs
查看文件 @
45eed44f
...
...
@@ -451,137 +451,3 @@ impl HYMqttTransport {
result
}
}
\ No newline at end of file
#[cfg(test)]
mod
tests
{
use
crate
::
hymqtt
::{
HYMqttTransport
,
HYPoint
,
HYPointInfo
};
use
chrono
::
prelude
::
*
;
use
serde_json
::
json
;
#[test]
fn
test_parse_hy_mqtt_csv
()
{
let
tp
=
HYMqttTransport
::
from_csv
(
"tests/ttu-test.csv"
)
.unwrap
();
assert_eq!
(
tp
.name
,
"HYMQTT测试"
);
assert_eq!
(
tp
.mqtt_broker
,
(
"127.0.0.1"
.to_string
(),
1883u16
));
assert_eq!
(
tp
.read_topic
,
"gwIn/read"
);
assert_eq!
(
tp
.write_topic
,
"gwOut/write"
);
assert_eq!
(
tp
.user_name
.unwrap
(),
"admin"
);
assert_eq!
(
tp
.user_password
.unwrap
(),
"admin"
);
assert_eq!
(
tp
.app_name
,
"plcc"
);
assert_eq!
(
tp
.poll_time
,
1000
);
assert
!
(
tp
.is_poll
);
assert_eq!
(
tp
.point_id
,
9001
);
assert_eq!
(
tp
.is_new
,
false
);
assert_eq!
(
tp
.point_id_to_pos
.len
(),
10
);
println!
(
"{:?}"
,
tp
.point_id_to_pos
);
println!
(
"{:?}"
,
tp
.data_configure
);
println!
(
"{:?}"
,
tp
.model_to_pos
);
println!
(
"{:?}"
,
tp
.device_configure
);
}
#[test]
fn
test_json
()
{
let
fmt
=
"
%
Y-
%
m-
%d
T
%
H:
%
M:
%
S
%.3f
%
z"
;
let
now
:
DateTime
<
Local
>
=
Local
::
now
();
let
dft
=
now
.format
(
fmt
);
let
str_date
=
dft
.to_string
();
println!
(
"time: {}"
,
str_date
);
let
name
=
"macc"
.to_string
();
let
tp
=
HYPoint
{
not_realtime
:
false
,
device_id
:
0
,
point_id
:
0
,
point_info
:
HYPointInfo
{
name
:
"MACC"
.to_string
(),
r
#
type
:
"float"
.to_string
(),
unit
:
""
.to_string
(),
deadzone
:
"0"
.to_string
(),
ratio
:
"0"
.to_string
(),
isReport
:
"0"
.to_string
(),
userdefine
:
"0"
.to_string
(),
},
};
let
tp
=
vec!
[
tp
.point_info
.clone
(),
tp
.point_info
];
let
register
=
json!
({
"token"
:
123
,
"timestamp"
:
name
,
"body"
:
tp
,
});
let
mut
bodys
=
json!
([]);
for
i
in
0
..
3
{
let
body
=
json!
({
"model"
:
i
,
"port"
:
i
,
});
bodys
.as_array_mut
()
.unwrap
()
.push
(
body
);
}
// register.as_object_mut().unwrap().insert("Vec[body]".to_string(), bodys);
let
register
=
json!
([
register
,
bodys
]);
let
v
=
serde_json
::
to_string
(
&
register
)
.unwrap
();
println!
(
"{}"
,
v
);
// {
// "Vec[body]": [
// { "model": 0,
// "port": 0
// },
// { "model": 1,
// "port": 1
// },
// { "model": 2,
// "port": 2
// }
// ],
// "body": [
// { "deadzone": "0", "isReport": "0", "name": "MACC", "ratio": "0",
// "type": "float", "unit": "", "userdefine": "0"
// },
// { "deadzone": "0", "isReport": "0", "name": "MACC", "ratio": "0",
// "type": "float", "unit": "", "userdefine": "0"
// }
// ],
// "timestamp": "2022-12-02T20:39:55.966+0800",
// "token": 123
// }
}
// 测试json用serde_json解析
// 结论:时间好像差不多,但是serde_json解析json的速度还稍微有点慢
#[test]
fn
test_serde
()
{
let
tp
=
HYPoint
{
not_realtime
:
false
,
device_id
:
0
,
point_id
:
0
,
point_info
:
HYPointInfo
{
name
:
"MACC"
.to_string
(),
r
#
type
:
"float"
.to_string
(),
unit
:
""
.to_string
(),
deadzone
:
"0"
.to_string
(),
ratio
:
"0"
.to_string
(),
isReport
:
"0"
.to_string
(),
userdefine
:
"0"
.to_string
(),
},
};
let
mut
bodys
=
json!
([]);
for
_i
in
0
..
500
{
let
body
=
json!
(
tp
);
bodys
.as_array_mut
()
.unwrap
()
.push
(
body
);
}
let
v
=
serde_json
::
to_string
(
&
bodys
)
.unwrap
();
// 解析json,记录时间
let
begin
=
Local
::
now
();
for
_
in
0
..
10
{
let
test_json
:
serde_json
::
Value
=
serde_json
::
from_str
(
&
v
)
.unwrap
();
for
body
in
test_json
.as_array
()
.unwrap
()
{
//let name = body["point_info"]["name"].as_str().unwrap();
let
point
:
HYPoint
=
serde_json
::
from_value
(
body
.clone
())
.unwrap
();
let
_name
=
&
point
.point_info.name
;
// println!("{:?}", point);
}
}
let
end
=
Local
::
now
();
let
duration
=
end
-
begin
;
println!
(
"duration: {:?}"
,
duration
);
}
}
eig-domain/src/iec104.rs
查看文件 @
45eed44f
...
...
@@ -1051,90 +1051,3 @@ impl Iec104Point {
})
}
}
\ No newline at end of file
#[cfg(test)]
mod
tests
{
use
std
::
collections
::
HashMap
;
use
crate
::
iec104
::
Iec104ClientTp
;
use
crate
::
Iec104ServerTp
;
#[test]
fn
test_iec_client_from_csv
()
{
let
tp
=
Iec104ClientTp
::
from_csv
(
"tests/iec104c-test1.csv"
)
.unwrap
();
assert_eq!
(
tp
.name
,
"iec104测试通道1"
);
assert_eq!
(
tp
.tcp_server
.
0
,
"127.0.0.1"
);
assert_eq!
(
tp
.tcp_server
.
1
,
2404
);
assert_eq!
(
tp
.yx_data_type
,
1
);
assert_eq!
(
tp
.yc_data_type
,
13
);
assert_eq!
(
tp
.connection.originator_address
,
0
);
assert_eq!
(
tp
.connection.common_address
,
1
);
assert_eq!
(
tp
.connection.point_id
,
109001
);
assert_eq!
(
tp
.connection.cot_field_length
,
2
);
assert_eq!
(
tp
.connection.common_address_field_length
,
2
);
assert_eq!
(
tp
.connection.max_idle_time
,
20000
);
assert_eq!
(
tp
.connection.max_time_no_ack_received
,
15000
);
assert_eq!
(
tp
.connection.max_time_no_ack_sent
,
10000
);
assert_eq!
(
tp
.connection.data_configure
.len
(),
10
);
assert
!
(
!
tp
.connection.is_control_with_time
);
assert
!
(
!
tp
.connection.direct_yk
);
assert
!
(
!
tp
.connection.direct_yt
);
assert_eq!
(
tp
.connection.data_configure
[
0
]
.ioa
,
1
);
assert_eq!
(
tp
.connection.data_configure
[
0
]
.point_id
,
104001
);
assert
!
(
!
tp
.connection.data_configure
[
0
]
.is_yx
);
assert_eq!
(
tp
.connection.data_configure
[
0
]
.control_ioa
,
Some
(
6001
));
assert_eq!
(
tp
.connection.call_time
,
Some
(
10000
));
assert_eq!
(
tp
.connection.call_counter_time
,
Some
(
10000
));
assert
!
(
tp
.connection.is_client
);
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
Iec104ClientTp
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
}
#[test]
fn
test_iec_server_from_csv
()
{
let
tp
=
Iec104ServerTp
::
from_csv
(
"tests/iec104d-test1.csv"
)
.unwrap
();
assert_eq!
(
tp
.name
,
"iec104服务通道1"
);
assert_eq!
(
tp
.tcp_server_port
,
2404
);
assert_eq!
(
tp
.yx_data_type
,
1
);
assert_eq!
(
tp
.yc_data_type
,
13
);
assert_eq!
(
tp
.connections
.len
(),
2
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.originator_address
,
0
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.common_address
,
1
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.point_id
,
102404
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.cot_field_length
,
2
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.common_address_field_length
,
2
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.max_idle_time
,
20000
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.max_time_no_ack_received
,
15000
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.max_time_no_ack_sent
,
10000
);
assert_eq!
(
tp
.connections
[
0
]
.
1
.data_configure
.len
(),
10
);
assert
!
(
!
tp
.connections
[
0
]
.
1
.is_control_with_time
);
assert
!
(
!
tp
.connections
[
0
]
.
1
.direct_yk
);
assert
!
(
!
tp
.connections
[
0
]
.
1
.direct_yt
);
assert
!
(
!
tp
.connections
[
0
]
.
1
.is_client
);
assert
!
(
!
tp
.connections
[
0
]
.
1
.data_configure
[
0
]
.is_yx
);
assert
!
(
tp
.connections
[
0
]
.
1
.data_configure
[
0
]
.control_ioa
.is_some
());
assert_eq!
(
tp
.connections
[
0
]
.
1
.call_time
,
Some
(
10000
));
assert_eq!
(
tp
.connections
[
0
]
.
1
.call_counter_time
,
Some
(
10000
));
assert
!
(
tp
.connections
[
1
]
.
1
.data_configure
[
0
]
.control_ioa
.is_none
());
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
Iec104ServerTp
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
}
#[test]
fn
test_export_iec_server_model
()
{
let
tp
=
Iec104ServerTp
::
from_file
(
"tests/iec104d-transport-example.xlsx"
)
.unwrap
();
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
Iec104ServerTp
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
}
#[test]
fn
test_export_iec_server_model2
()
{
let
tp
=
Iec104ServerTp
::
from_file
(
"tests/iec104d-unknown-ip.xlsx"
)
.unwrap
();
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
Iec104ServerTp
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
}
}
eig-domain/src/lib.rs
查看文件 @
45eed44f
...
...
@@ -1802,237 +1802,3 @@ fn deserialize_enum_or_unknown<'de, E: EnumFull, D: serde::Deserializer<'de>>(
d.deserialize_any(DeserializeEnumVisitor(PhantomData))
}
\ No newline at end of file
#[cfg(test)]
mod tests {
// use bytes::{Buf, BufMut, BytesMut};
// use protobuf::Message;
// use protobuf::error::WireError;
// use crate::PbMessage;
use crate::from_csv2;
use crate::{from_csv_bytes2, Measurement, PbSetIntPoint, TransportType};
// fn parse_pb_message(buf: &BytesMut) -> ProtobufResult<(usize, PbMessage)> {
// let mut is = CodedInputStream::from_bytes(buf);
// let mut msg = PbMessage::new();
// while !is.eof()? {
// let (field_number, _) = is.read_tag_unpack()?;
// match field_number {
// 1 => {
// let mut topic = String::new();
// is.read_string_into(&mut topic)?;
// msg.set_topic(topic);
// }
// 2 => {
// let mut content = Vec::new();
// is.read_bytes_into(&mut content)?;
// msg.set_content(content);
// break;
// }
// _ => {
// return Err(WireError(WireError::IncorrectTag(
// field_number,
// )));
// }
// };
// }
// Ok((is.pos() as usize, msg))
// }
// #[test]
// fn test_protobuf_parse() {
// let mut msg1 = PbMessage::new();
// msg1.set_topic("
t1
".to_string());
// msg1.set_content(b"
abcdefg
".to_vec());
// let mut msg2 = PbMessage::new();
// msg2.set_topic("
t2
".to_string());
// msg2.set_content(b"
123
abcdefg
".to_vec());
// let bytes1 = msg1.write_to_bytes().unwrap();
// let bytes2 = msg2.write_to_bytes().unwrap();
// let mut buf = BytesMut::with_capacity(bytes1.len() + bytes2.len() + 2);
// buf.extend_from_slice(bytes1.as_slice());
// // 加入一些干扰的数据
// buf.extend_from_slice(b"
11
");
// let len = bytes2.len();
// // 第二个对象数据不全
// buf.extend_from_slice(&bytes2[0..len - 1]);
// let mut result = Vec::with_capacity(2);
// while !buf.is_empty() {
// match parse_pb_message(&buf) {
// Ok((needed, msg)) => {
// buf.advance(needed);
// result.push(msg);
// }
// Err(WireError(WireError::UnexpectedEof)) => {
// break;
// }
// Err(e) => {
// println!("
{:
?
}
", e);
// buf.advance(1);
// }
// }
// }
// // 把第二个对象的数据补全
// buf.put_u8(bytes2[len - 1]);
// while !buf.is_empty() {
// match parse_pb_message(&buf) {
// Ok((needed, msg)) => {
// buf.advance(needed);
// result.push(msg);
// }
// Err(WireError(WireError::UnexpectedEof)) => {
// break;
// }
// Err(e) => {
// println!("
{:
?
}
", e);
// buf.advance(1);
// }
// }
// }
// assert_eq!(result.len(), 2);
// assert_eq!(result[0], msg1);
// assert_eq!(result[1], msg2);
// }
#[test]
fn test_proto_serde() {
let mut o = PbSetIntPoint::new();
o.set_pointId(1);
let s = serde_json::to_string(&o).unwrap();
assert!(!s.is_empty());
}
#[test]
fn test_point_from_csv() {
let (points, _) = from_csv2("
tests
/
points
-
test1
.csv
", false).unwrap();
assert_eq!(points.len(), 10);
for i in 100001..100009 {
let p = points.get(&i).unwrap();
assert_eq!(p.get_init_discrete(), (i - 100000) as i64);
}
let p = points.get(&100009).unwrap();
assert_eq!(p.get_init_discrete(), -1);
let p = points.get(&100010).unwrap();
assert_eq!(p.get_init_analog(), 10.99);
let mut csv_str = String::new();
let mut i = 1;
for p in points.values() {
csv_str.push_str(i.to_string().as_str());
csv_str.push(',');
csv_str.push_str(p.to_string().as_str());
csv_str.push('
\n
');
i += 1;
}
let (points2, _) = from_csv_bytes2(csv_str.as_bytes(), false, false).unwrap();
assert_eq!(points, points2);
}
#[test]
fn test_from_csv_bytes() {
let mut p = Measurement {
point_id: 1000,
point_name: "
abc
".to_string(),
alias_id: "
abcd
".to_string(),
is_discrete: false,
is_computing_point: false,
expression: "".to_string(),
trans_expr: "".to_string(),
inv_trans_expr: "".to_string(),
change_expr: "".to_string(),
zero_expr: "".to_string(),
data_unit: "".to_string(),
unit: crate::DataUnit::UnitOne,
upper_limit: f64::MAX,
lower_limit: f64::MIN,
alarm_level1_expr: "".to_string(),
alarm_level1: None,
alarm_level2_expr: "".to_string(),
alarm_level2: None,
is_realtime: false,
is_soe: false,
is_remote: false,
init_value: 0,
desc: "".to_string(),
};
let mut s = format!("
1
,{}
", p.to_string());
s.push('
\n
');
p.point_id = 2000;
p.data_unit = "
kV
".to_string();
s.push_str(format!("
2
,{}
", p.to_string()).as_str());
s.push('
\n
');
println!("
{}
", s);
let (r, _) = from_csv_bytes2(s.into_bytes().as_slice(), false, false).unwrap();
assert_eq!(2, r.len());
assert_eq!(1000, r.get(&1000).unwrap().point_id);
assert_eq!(2000, r.get(&2000).unwrap().point_id);
assert_eq!("
kV
", r.get(&2000).unwrap().data_unit);
}
#[test]
fn test_parse_radix() {
let s = "
0x00010000
";
let r = u32::from_str_radix(s.trim_start_matches("
0
x
"), 16).unwrap();
assert_eq!(0x00_01_00_00, r);
let s = "
0x00C2000C
";
let r = u32::from_str_radix(s.trim_start_matches("
0
x
"), 16).unwrap();
assert_eq!(0x00_C2_00_0C, r);
let bytes = r.to_be_bytes();
println!("
{:
02
x
?
}
", bytes);
}
#[test]
fn test_transport_type() {
assert_eq!(
TransportType::ModbusTcpClient,
TransportType::from("
ModbusTcpClient
")
);
assert_eq!(
TransportType::ModbusTcpServer,
TransportType::from("
ModbusTcpServer
")
);
assert_eq!(
TransportType::Iec104Client,
TransportType::from("
Iec104Client
")
);
assert_eq!(
TransportType::Iec104Server,
TransportType::from("
Iec104Server
")
);
assert_eq!(TransportType::Unknown, TransportType::from("
xx
"));
assert_eq!(1, TransportType::ModbusTcpClient as u16);
assert_eq!(2, TransportType::ModbusTcpServer as u16);
assert_eq!(11, TransportType::Iec104Client as u16);
assert_eq!(12, TransportType::Iec104Server as u16);
assert_eq!(100, TransportType::Unknown as u16);
}
#[test]
#[allow(unused_variables)]
fn serde_test() {
// let m = init_discrete_point(100001,0);
// let byte = serde_json::to_vec(&vec![m]).unwrap();
// let m_d = serde_json::from_slice::<Vec<Measurement>>(&byte).unwrap();
let num_f64 = 1.;
let byte = serde_json::to_vec(&num_f64).unwrap();
let num_f64_d = serde_json::from_slice::<f64>(&byte).unwrap();
// let num_f64 = f64::NAN;
// let byte = serde_json::to_vec(&num_f64).unwrap();
// let num_f64_d = serde_json::from_slice::<f64>(&byte).unwrap();
let num_f64 = f64::INFINITY;
let byte = serde_cbor::to_vec(&num_f64).unwrap();
let num_f64_d = serde_cbor::from_slice::<f64>(&byte).unwrap();
}
#[test]
fn test_parse_exp() {
let a = "
0.000000e0
".to_string();
let b = a.parse::<f64>().unwrap();
println!("
{:
?
}
", b);
}
}
eig-domain/src/memory.rs
查看文件 @
45eed44f
...
...
@@ -568,28 +568,3 @@ impl MemData {
})
}
}
\ No newline at end of file
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
parse_file
()
{
let
file
=
"tests/posix-memory-transport-test1.xlsx"
;
let
tp
=
MemoryPosixTp
::
from_file
(
file
);
assert
!
(
tp
.is_ok
());
let
tp
=
tp
.unwrap
();
assert_eq!
(
"posix-memory-transport-file"
,
tp
.path
.unwrap
());
}
#[test]
fn
parse_file_systemv
()
{
let
file
=
"tests/systemv-memory-transport-test1.xlsx"
;
let
tp
=
MemorySystemVTp
::
from_file
(
file
);
let
tp
=
tp
.unwrap
();
assert_eq!
(
"/"
,
tp
.path
);
}
}
\ No newline at end of file
eig-domain/src/modbus.rs
查看文件 @
45eed44f
差异被折叠。
点击展开。
eig-domain/src/mqtt.rs
查看文件 @
45eed44f
...
...
@@ -508,120 +508,3 @@ pub fn merge_json(tags: &[String], values: &[Value]) -> Value {
}
result
}
\ No newline at end of file
#[cfg(test)]
mod
tests
{
use
std
::
collections
::
HashMap
;
use
serde_json
::{
json
,
Value
};
use
crate
::
from_file
;
use
crate
::
mqtt
::{
merge_json
,
MqttTransport
,
split_json
};
use
crate
::
utils
::
check_mqtt_transport
;
#[test]
fn
test_parse_mqtt_csv
()
{
let
tp
=
MqttTransport
::
from_csv
(
"tests/mqtt-test1.csv"
)
.unwrap
();
assert_eq!
(
tp
.name
,
"Mqtt测试通道"
);
assert_eq!
(
tp
.mqtt_broker
,
(
"127.0.0.1"
.to_string
(),
1883u16
));
assert_eq!
(
tp
.read_topic
,
"gwIn/read"
);
assert_eq!
(
tp
.write_topic
,
"gwOut/write"
);
assert_eq!
(
tp
.point_id
,
9001
);
assert_eq!
(
tp
.point_ids
.len
(),
10
);
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
MqttTransport
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
let
tp
=
MqttTransport
::
from_csv
(
"tests/mqtt-test2.csv"
)
.unwrap
();
assert_eq!
(
tp
.user_name
,
Some
(
String
::
from
(
"admin"
)));
assert_eq!
(
tp
.user_password
,
Some
(
String
::
from
(
"admin"
)));
assert
!
(
tp
.is_json
);
assert
!
(
tp
.is_transfer
);
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
MqttTransport
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
let
tp
=
MqttTransport
::
from_csv
(
"tests/mqtt-test3.csv"
)
.unwrap
();
assert_eq!
(
tp
.point_ids
.len
(),
4
);
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
MqttTransport
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
let
tp
=
MqttTransport
::
from_csv
(
"tests/mqtt-transport-db1.csv"
)
.unwrap
();
assert_eq!
(
tp
.point_ids
.len
(),
6
);
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2
=
MqttTransport
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
}
#[test]
fn
test_export_mqtt_model
()
{
let
tp1
=
MqttTransport
::
from_csv
(
"tests/mqtt-test1.csv"
)
.unwrap
();
let
tp1_export
=
tp1
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp1_parse_from_export
=
MqttTransport
::
from_csv_bytes
(
tp1_export
.as_bytes
());
assert_eq!
(
tp1_parse_from_export
,
Ok
(
tp1
));
let
tp2
=
MqttTransport
::
from_csv
(
"tests/mqtt-test2.csv"
)
.unwrap
();
let
tp2_export
=
tp2
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp2_parse_from_export
=
MqttTransport
::
from_csv_bytes
(
tp2_export
.as_bytes
());
assert_eq!
(
tp2_parse_from_export
,
Ok
(
tp2
));
}
#[test]
fn
test_parse_with_custom_json
()
{
let
v1
=
json!
({
"code"
:
200
,
"success"
:
true
,
"payload"
:
{
"features"
:
[
"serde"
,
"json"
],
"homepage"
:
null
}
});
let
map
=
split_json
(
&
v1
);
let
keys
:
Vec
<
String
>
=
map
.keys
()
.cloned
()
.collect
();
let
values
:
Vec
<
Value
>
=
map
.values
()
.cloned
()
.collect
();
let
v2
=
merge_json
(
&
keys
,
&
values
);
assert_eq!
(
v1
,
v2
);
let
tp
=
MqttTransport
::
from_csv
(
"tests/mqtt-test4.csv"
)
.unwrap
();
let
s
=
tp
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
// println!("{}", s);
let
tp2
=
MqttTransport
::
from_csv_bytes
(
s
.as_bytes
())
.unwrap
();
assert_eq!
(
tp
,
tp2
);
// println!("{:?}", tp);
assert_eq!
(
tp
.point_ids
.len
(),
10
);
assert_eq!
(
tp
.json_filters
.unwrap
()
.len
(),
1
);
assert_eq!
(
tp
.json_tags
.unwrap
()
.len
(),
3
);
}
#[test]
fn
test_custom_json2
()
{
let
tp1
=
MqttTransport
::
from_csv
(
"tests/mqtt-test5.csv"
)
.unwrap
();
assert
!
(
tp1
.json_tags
.is_some
());
assert_eq!
(
1
,
tp1
.json_tags
.as_ref
()
.unwrap
()
.len
());
let
tags
=
tp1
.json_tags
.as_ref
()
.unwrap
()
.get
(
"[0]"
);
assert
!
(
tags
.is_some
());
assert_eq!
(
10
,
tags
.unwrap
()
.len
());
let
tp1_export
=
tp1
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
let
tp1_parse_from_export
=
MqttTransport
::
from_csv_bytes
(
tp1_export
.as_bytes
());
assert_eq!
(
tp1_parse_from_export
,
Ok
(
tp1
));
let
r
=
MqttTransport
::
from_csv
(
"tests/mqtt-test6.csv"
);
assert_eq!
(
r
,
Err
((
2
,
6
)));
}
#[test]
fn
test_custom_json3
()
{
let
tp1
=
MqttTransport
::
from_file
(
"tests/mqtt-transport-nb1.xlsx"
);
assert
!
(
tp1
.is_ok
());
let
tp1
=
tp1
.unwrap
();
assert
!
(
tp1
.json_tags
.is_some
());
let
(
points
,
_
)
=
from_file
(
"tests/points-nb1.xlsx"
)
.unwrap
();
let
r
=
check_mqtt_transport
(
&
points
,
&
tp1
);
assert_eq!
(
r
,
Ok
(()));
let
tp1_export
=
tp1
.export_csv
(
&
HashMap
::
with_capacity
(
0
));
// println!("{}", tp1_export);
let
tp1_parse_from_export
=
MqttTransport
::
from_csv_bytes
(
tp1_export
.as_bytes
());
assert_eq!
(
tp1_parse_from_export
,
Ok
(
tp1
));
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论