Skip to content

Commit

Permalink
fix ContainedIn (#27)
Browse files Browse the repository at this point in the history
* Add test for non-containment of depth 1
* Change containment edge case to be at size 0

Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg authored Mar 19, 2024
1 parent 02a3729 commit e985283
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
18 changes: 4 additions & 14 deletions pkg/hypercube/hypercubeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ func (c *CanonicalSet) Subtract(other *CanonicalSet) *CanonicalSet {
}
}

func (c *CanonicalSet) getIntervalSetUnion() *interval.CanonicalSet {
res := interval.NewCanonicalSet()
for k := range c.layers {
res.Union(k)
}
return res
}

// ContainedIn returns true ic other contained in c
func (c *CanonicalSet) ContainedIn(other *CanonicalSet) (bool, error) {
if c == other {
Expand All @@ -179,13 +171,11 @@ func (c *CanonicalSet) ContainedIn(other *CanonicalSet) (bool, error) {
if c.dimensions != other.dimensions {
return false, errors.New("ContainedIn mismatch between num of dimensions for input args")
}
if c.dimensions == 1 {
if len(c.layers) != 1 || len(other.layers) != 1 {
return false, errors.New("unexpected object of dimension size 1")
if c.dimensions == 0 {
if len(c.layers) != 0 || len(other.layers) != 0 {
return false, errors.New("unexpected non-empty object of dimension size 0")
}
cInterval := c.getIntervalSetUnion()
otherInterval := other.getIntervalSetUnion()
return cInterval.ContainedIn(otherInterval), nil
return true, nil
}

isSubsetCount := 0
Expand Down
7 changes: 7 additions & 0 deletions pkg/hypercube/hypercubeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ func TestContainedIn(t *testing.T) {
checkContained(t, b, a, false)
}

func TestContainedIn1(t *testing.T) {
checkContained(t, cube(1, 3), cube(2, 4), false)
checkContained(t, cube(2, 4), cube(1, 3), false)
checkContained(t, cube(1, 3), cube(1, 4), true)
checkContained(t, cube(1, 4), cube(1, 3), false)
}

func TestContainedIn2(t *testing.T) {
c := union(
cube(1, 100, 200, 300),
Expand Down

0 comments on commit e985283

Please sign in to comment.