added primary header tests
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
||||
pub fn main() {
|
||||
gleeunit.main()
|
||||
}
|
||||
|
||||
// gleeunit test functions end in `_test`
|
||||
pub fn hello_world_test() {
|
||||
1
|
||||
|> should.equal(1)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import gleeunit/should
|
||||
import space_packet/primary_hdr
|
||||
|
||||
pub fn packet_type_from_int_test() {
|
||||
primary_hdr.packet_type_from_int(0)
|
||||
|> should.equal(primary_hdr.Telemetry)
|
||||
|
||||
primary_hdr.packet_type_from_int(1)
|
||||
|> should.equal(primary_hdr.Command)
|
||||
|
||||
primary_hdr.packet_type_from_int(555)
|
||||
|> should.equal(primary_hdr.Telemetry)
|
||||
}
|
||||
|
||||
pub fn packet_type_to_int_test() {
|
||||
primary_hdr.packet_type_to_int(primary_hdr.Command)
|
||||
|> should.equal(1)
|
||||
|
||||
primary_hdr.packet_type_to_int(primary_hdr.Telemetry)
|
||||
|> should.equal(0)
|
||||
}
|
||||
|
||||
pub fn packet_type_to_string() {
|
||||
primary_hdr.packet_type_to_string(primary_hdr.Command)
|
||||
|> should.equal("Command")
|
||||
|
||||
primary_hdr.packet_type_to_string(primary_hdr.Telemetry)
|
||||
|> should.equal("Telemetry")
|
||||
}
|
||||
|
||||
pub fn sequence_flags_from_int_test() {
|
||||
primary_hdr.sequence_flags_from_int(0b00)
|
||||
|> should.equal(primary_hdr.Continuation)
|
||||
|
||||
primary_hdr.sequence_flags_from_int(0b01)
|
||||
|> should.equal(primary_hdr.FirstSegment)
|
||||
|
||||
primary_hdr.sequence_flags_from_int(0b10)
|
||||
|> should.equal(primary_hdr.LastSegment)
|
||||
|
||||
primary_hdr.sequence_flags_from_int(0b11)
|
||||
|> should.equal(primary_hdr.Unsegmented)
|
||||
}
|
||||
|
||||
pub fn sequence_flags_to_int_test() {
|
||||
primary_hdr.sequence_flags_to_int(primary_hdr.Continuation)
|
||||
|> should.equal(0b00)
|
||||
|
||||
primary_hdr.sequence_flags_to_int(primary_hdr.FirstSegment)
|
||||
|> should.equal(0b01)
|
||||
|
||||
primary_hdr.sequence_flags_to_int(primary_hdr.LastSegment)
|
||||
|> should.equal(0b10)
|
||||
|
||||
primary_hdr.sequence_flags_to_int(primary_hdr.Unsegmented)
|
||||
|> should.equal(0b11)
|
||||
}
|
||||
|
||||
pub fn sequence_flags_to_string_test() {
|
||||
primary_hdr.sequence_flags_to_string(primary_hdr.Continuation)
|
||||
|> should.equal("Continuation")
|
||||
|
||||
primary_hdr.sequence_flags_to_string(primary_hdr.FirstSegment)
|
||||
|> should.equal("First Segment")
|
||||
|
||||
primary_hdr.sequence_flags_to_string(primary_hdr.LastSegment)
|
||||
|> should.equal("Last Segment")
|
||||
|
||||
primary_hdr.sequence_flags_to_string(primary_hdr.Unsegmented)
|
||||
|> should.equal("Unsegmented")
|
||||
}
|
||||
|
||||
pub fn from_bit_array_test() {
|
||||
let valid_bit_array = <<
|
||||
0b000:size(3), 0b0:size(1), 0b0:size(1), 0x200:size(11), 0b11:size(2),
|
||||
0x01:size(11), 0x01:size(16),
|
||||
>>
|
||||
let expected_hdr =
|
||||
primary_hdr.PrimaryHeader(
|
||||
version: 0,
|
||||
sp_type: primary_hdr.Telemetry,
|
||||
sec_hdr_flag: False,
|
||||
apid: 0x200,
|
||||
seq_flag: primary_hdr.Unsegmented,
|
||||
seq_count: 1,
|
||||
packet_len: 1,
|
||||
)
|
||||
|
||||
primary_hdr.from_bit_array(valid_bit_array)
|
||||
|> should.be_ok()
|
||||
|> should.equal(expected_hdr)
|
||||
}
|
||||
|
||||
pub fn from_bit_array_fail_test() {
|
||||
let invalid_bit_array = <<0x00:size(41)>>
|
||||
|
||||
primary_hdr.from_bit_array(invalid_bit_array)
|
||||
|> should.be_error()
|
||||
|> should.equal(primary_hdr.InvalidSize)
|
||||
}
|
||||
|
||||
pub fn to_bit_array_test() {
|
||||
let expected_bit_array = <<
|
||||
0b000:size(3), 0b0:size(1), 0b0:size(1), 0x200:size(11), 0b11:size(2),
|
||||
0x01:size(11), 0x01:size(16),
|
||||
>>
|
||||
let hdr =
|
||||
primary_hdr.PrimaryHeader(
|
||||
version: 0,
|
||||
sp_type: primary_hdr.Telemetry,
|
||||
sec_hdr_flag: False,
|
||||
apid: 0x200,
|
||||
seq_flag: primary_hdr.Unsegmented,
|
||||
seq_count: 1,
|
||||
packet_len: 1,
|
||||
)
|
||||
|
||||
primary_hdr.to_bit_array(hdr)
|
||||
|> should.equal(expected_bit_array)
|
||||
}
|
||||
Reference in New Issue
Block a user