mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 02:26:42 +00:00
last function (#17)
* last function * fix CI Co-authored-by: Ruidy <rnemausat@newstore.com>
This commit is contained in:
parent
edb3c09e43
commit
fb517f3b04
7 changed files with 36 additions and 14 deletions
5
.github/FUNDING.yml
vendored
5
.github/FUNDING.yml
vendored
|
|
@ -1,4 +1 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github: rjNemo # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
|
||||
github: rjNemo
|
||||
|
|
|
|||
14
.github/workflows/unit-test.yml
vendored
14
.github/workflows/unit-test.yml
vendored
|
|
@ -12,12 +12,12 @@ jobs:
|
|||
with:
|
||||
go-version: '1.18'
|
||||
- name: Run tests with coverage
|
||||
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
|
||||
run: go test -coverprofile=coverage.out -covermode=count ./...
|
||||
- uses: codecov/codecov-action@v2
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
|
||||
files: ./coverage.out # optional
|
||||
flags: unittests # optional
|
||||
name: codecov-umbrella # optional
|
||||
fail_ci_if_error: true # optional (default = false)
|
||||
verbose: true # optional (default = false)
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: ./coverage.out
|
||||
flags: unittests
|
||||
name: codecov-umbrella
|
||||
fail_ci_if_error: true
|
||||
verbose: true
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
FROM golang:1.18-alpine
|
||||
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GOOS linux
|
||||
|
||||
RUN apk update --no-cache
|
||||
|
||||
WORKDIR /lib
|
||||
|
|
@ -9,3 +11,4 @@ COPY go.* ./
|
|||
RUN go mod download
|
||||
|
||||
COPY . ./
|
||||
|
||||
|
|
|
|||
4
Makefile
4
Makefile
|
|
@ -1,7 +1,7 @@
|
|||
TEST = "go test ./... -coverpkg=./... -coverprofile coverage.out -covermode=atomic; go tool cover -func coverage.out; rm coverage.out"
|
||||
TEST = "go test ./... -coverpkg=./... -coverprofile coverage.out -covermode=count; go tool cover -func coverage.out; rm coverage.out"
|
||||
|
||||
build:
|
||||
docker build . -t underscore:latest
|
||||
docker build -t underscore:latest .
|
||||
|
||||
test: build
|
||||
docker run --name underscore --rm -i -t underscore sh -c $(TEST)
|
||||
|
|
|
|||
2
docs/themes/compose
vendored
2
docs/themes/compose
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 362af2409158972008f1dff8ee5e887d6ce88257
|
||||
Subproject commit 94194f5630e67d3fdbc5d4ae39ac027b0455d29a
|
||||
7
last.go
Normal file
7
last.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package underscore
|
||||
|
||||
// Last returns the last element of the slice
|
||||
func Last[T any](values []T) T {
|
||||
n := len(values)
|
||||
return values[n-1]
|
||||
}
|
||||
15
last_test.go
Normal file
15
last_test.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package underscore_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
u "github.com/rjNemo/underscore"
|
||||
)
|
||||
|
||||
func TestLast(t *testing.T) {
|
||||
nums := []int{1, 9, 2, 8, 3, 7, 4, 6, 5}
|
||||
want := 5
|
||||
assert.Equal(t, want, u.Last(nums))
|
||||
}
|
||||
Loading…
Reference in a new issue