Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rdfwriter/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/spdx/gordf/rdfloader/parser"
"github.com/spdx/gordf/uri"
"slices"
"strings"
)

Expand Down Expand Up @@ -80,6 +81,16 @@ func getUniqueTriples(triples []*parser.Triple) []*parser.Triple {
for key := range set {
retList = append(retList, set[key])
}
slices.SortFunc(retList, func(a, b *parser.Triple) int {
c := strings.Compare(a.Subject.String(), b.Subject.String())
if c == 0 {
c = strings.Compare(a.Predicate.String(), b.Predicate.String())
}
if c == 0 {
c = strings.Compare(a.Object.String(), b.Predicate.String())
}
return c
})
return retList
}

Expand Down
12 changes: 12 additions & 0 deletions rdfwriter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ func TestTopologicalSortTriples(t *testing.T) {
{Subject: nodes[0], Predicate: nodes[2], Object: nodes[3]},
{Subject: nodes[3], Predicate: nodes[4], Object: nodes[0]},
}
t.Logf("Got %d sortedTriples:", len(sortedTriples))
for k, v := range sortedTriples {
t.Logf(" sortedTriples[%v]=%s", k, v)
}
t.Logf("Want %d expectedTriples", len(expectedTriples))
for k, v := range expectedTriples {
t.Logf(" expectedTriples[%v]=%s", k, v)
}
t.Logf("Or %d anotherConfig", len(anotherConfig))
for k, v := range anotherConfig {
t.Logf(" anotherConfig[%v]=%s", k, v)
}
if !reflect.DeepEqual(sortedTriples, expectedTriples) && !reflect.DeepEqual(sortedTriples, anotherConfig) {
t.Errorf("sorted triples are not in correct order")
}
Expand Down