Skip to content

Commit

Permalink
add unit test for tag.RegisterCustom
Browse files Browse the repository at this point in the history
  • Loading branch information
flicaflow committed Nov 8, 2024
1 parent 1ded9ae commit 64b47fd
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions pkg/tag/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,70 @@ func TestSplitTag(t *testing.T) {

}

func TestRegisterCustom(t *testing.T) {

t.Run("Add new tag", func(t *testing.T) {
// Given a certain tag does not exist
_, err := FindByName("TestTag")
if err == nil {
t.Fatalf("expected TestTag to not exist")
}

// When a new tag is registered
TagTestTag := Tag{Group: 0x0063, Element: 0x0020}
RegisterCustom(Info{
Tag: TagTestTag,
VR: "UT",
Name: "TestTag",
VM: "1",
})

// Then the tag is now part of the tag collection
_, err = FindByName("TestTag")
if err != nil {
t.Fatalf("expected TestTag to be accessible with FindByName")
}
info, err := Find(TagTestTag)
if err != nil {
t.Fatalf("expected TestTag to be accessible with Find")
}
if info.VR != "UT" ||
info.Name != "TestTag" ||
info.VM != "1" {
t.Fatal("info of new registered tag is wrong")
}
})
t.Run("override existing tag", func(t *testing.T) {
// Given a tag already exists
TagTestTag := Tag{Group: 0x0010, Element: 0x0010} // this is the PatientName tag
info, err := Find(TagTestTag)
if err != nil {
t.Fatalf("expected TestTag to be accessible with Find")
}
if info.VR != "PN" {
t.Fatal("expected PatientName VR is originally PN")
}

// When the tag is registered with different content
RegisterCustom(Info{
Tag: TagTestTag,
VR: "LO", // originally this is PN
Name: "PatientName",
VM: "1",
})

// Then the tag information is overridden
info, err = Find(TagTestTag)
if err != nil {
t.Fatalf("expected TestTag to be accessible with Find")
}
if info.VR != "LO" {
t.Fatal("expected the VR to have changed to LO")
}
})

}

func BenchmarkFindMetaGroupLengthTag(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := Find(Tag{2, 0}); err != nil {
Expand Down

0 comments on commit 64b47fd

Please sign in to comment.