Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation and tests for DQL - unique() #2505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions docs/docs/reference/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ filter([1, 2, 3], (x) => x >= 2) = [2, 3]
filter(["yes", "no", "yas"], (x) => startswith(x, "y")) = ["yes", "yas"]
```

### `unique(array)`

Creates a new array with only unique values.

```js
unique([1, 3, 7, 3, 1]) => [1, 3, 7]
```

### `map(array, func)`

Applies the function to each element in the array, returning a list of the mapped results.
Expand Down
7 changes: 7 additions & 0 deletions src/test/function/aggregation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ describe("filter()", () => {
test("number list", () => expectEvals("filter(list(1, 2, 3), (k) => k >= 2)", [2, 3]));
});

describe("unique()", () => {
test("empty", () => expectEvals("unique([])", []));
test("single", () => expectEvals("unique([1])", [1]));
test("multiple unique", () => expectEvals("unique([1, 1, 1])", [1]));
test("multiple same", () => expectEvals("unique([1, 3, 7, 3, 1])", [1, 3, 7]));
Comment on lines +17 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the names for these tests flipped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah... It could be based on your perspective... The first test for a test case of multiple occurence of a unique value, and the second tests for multiple occurences of different but still a limited set of values.

Naming is hard... :-)

});

describe("min()", () => {
test("empty", () => expectEvals("min()", null));
test("single", () => expectEvals("min(6)", 6));
Expand Down
Loading