Skip to content

Commit

Permalink
Merge pull request #158 from Pix4D/sets-union
Browse files Browse the repository at this point in the history
sets: add Union()
  • Loading branch information
marco-m-pix4d authored Sep 25, 2024
2 parents 826ca44 + 88f6dce commit a55a812
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ See also the next section.

These suggestions apply to the development of any Concourse resource.

### Building a new image and ensuring that the pipeline picks it up
### Building a new image and ensuring that the pipeline picks it up

After the local tests are passing, the quickest way to test in a pipeline the freshly pushed version of the Docker image used to be the `fly check-resource-type` command. Unfortunately somewhere in the Concourse 7.6.x series this broke (details: [registry-image-resource #316](https://github.com/concourse/registry-image-resource/issues/316)).

Expand All @@ -248,7 +248,7 @@ You can follow two steps:
1. `fly set-pipeline` with a check_interval for the resource type of 1m instead of the recommended 24h.
2. `fly clear-version`.

For example, assuming that the test pipeline is called `cogito-test`, that the resource in the pipeline is called `cogito` and that there is a job called `motormouse` (all this is true by using the sample pipeline [pipelines/cogito.yml](./pipelines/cogito.yml)),
For example, assuming that the test pipeline is called `cogito-test`, that the resource in the pipeline is called `cogito` and that there is a job called `motormouse` (all this is true by using the sample pipeline [pipelines/cogito.yml](./pipelines/cogito.yml)).

Step 1:

Expand All @@ -268,7 +268,7 @@ Step 2 (the sleep is fundamental to let check_every expire):
```
$ task test:all docker:build docker:smoke docker:push &&
fly -t cogito clear-versions --resource-type=cogito-test/cogito &&
echo "sleeping and hoping :-(" &&
echo "sleeping and hoping :-(" &&
sleep 70 &&
fly -t cogito trigger-job -j cogito-test/motormouse -w
```
Expand Down Expand Up @@ -336,7 +336,7 @@ Update the expired secrets as follows.
## Regenerate your GitHub personal access token (PAT)

1. Go to [Settings | Tokens](https://github.com/settings/tokens) for your account.
2. Create or regenerate a token with name `test-cogito`, with scope "repo:status". Set an expiration of 90 days.
2. Create or regenerate a token with name `test-cogito`, with scope `repo:status`. Set an expiration of 90 days.
3. Copy the token.

## Regenerate a Google Chat hook
Expand Down
12 changes: 12 additions & 0 deletions sets/sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ func (s *Set[T]) Intersection(x *Set[T]) *Set[T] {
}
return result
}

// Union returns a set containing all the elements of s and x.
func (s *Set[T]) Union(x *Set[T]) *Set[T] {
result := New[T](max(s.Size(), x.Size()))
for item := range s.items {
result.items[item] = struct{}{}
}
for item := range x.items {
result.items[item] = struct{}{}
}
return result
}
59 changes: 59 additions & 0 deletions sets/sets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,65 @@ func TestIntersection(t *testing.T) {
}
}

func TestUnion(t *testing.T) {
type testCase struct {
name string
s *sets.Set[int]
x *sets.Set[int]
wantList []int
}

test := func(t *testing.T, tc testCase) {
result := tc.s.Union(tc.x)
sorted := result.OrderedList()

qt.Assert(t, qt.DeepEquals(sorted, tc.wantList))
}

testCases := []testCase{
{
name: "both empty",
s: sets.From[int](),
x: sets.From[int](),
wantList: []int{},
},
{
name: "empty x",
s: sets.From(1, 2),
x: sets.From[int](),
wantList: []int{1, 2},
},
{
name: "empty s",
s: sets.From[int](),
x: sets.From(1, 2),
wantList: []int{1, 2},
},
{
name: "identical",
s: sets.From(1, 2),
x: sets.From(1, 2),
wantList: []int{1, 2},
},
{
name: "all different",
s: sets.From(1, 3),
x: sets.From(2, 4),
wantList: []int{1, 2, 3, 4},
},
{
name: "partial overlap",
s: sets.From(1, 3),
x: sets.From(3, 5),
wantList: []int{1, 3, 5},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) { test(t, tc) })
}
}

func TestRemoveFound(t *testing.T) {
type testCase struct {
name string
Expand Down

0 comments on commit a55a812

Please sign in to comment.