Skip to content

Commit 4304c44

Browse files
authoredDec 19, 2018
project ci conf (#1)
project ci conf
1 parent 184fc1b commit 4304c44

12 files changed

+230
-0
lines changed
 

‎.codacy.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
exclude_paths:
3+
- '**/*.md'

‎.codecov.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: yes
4+
5+
coverage:
6+
round: up
7+
range: 0..10
8+
precision: 2
9+
10+
status:
11+
project: yes
12+
patch: yes
13+
changes: yes
14+
15+
comment:
16+
layout: "reach, diff, flags, files"
17+
behavior: default
18+
require_changes: false # if true: only post the comment if coverage changes
19+
require_base: yes # [yes :: must have a base report to post]
20+
require_head: yes # [yes :: must have a head report to post]
21+
branches: null

‎.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@
1010

1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
13+
14+
# JetBrains
15+
.idea/
16+
17+
# vs code
18+
.vscode/
19+
20+
# mac
21+
.DS_Store

‎.travis.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: go
2+
3+
go:
4+
- "1.11.x"
5+
6+
go_import_path: leetcode
7+
8+
install:
9+
- go get -t -v ./...
10+
11+
script:
12+
- go test ./... -race -coverprofile=coverage.txt -covermode=atomic
13+
14+
after_success:
15+
- bash <(curl -s https://codecov.io/bash)
16+
17+
branches:
18+
only:
19+
- master

‎Makefile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Basic go commands
2+
GOCMD=go
3+
GOBUILD=$(GOCMD) build
4+
GOCLEAN=$(GOCMD) clean
5+
GOTEST=$(GOCMD) test
6+
GOGET=$(GOCMD) get
7+
8+
test:
9+
@echo "unit test"
10+
$(GOTEST) -v ./...
11+
12+
clean:
13+
@echo "clean test cache"
14+
$(GOCLEAN) -testcache

‎ut.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
function cleanTestCache() {
4+
go clean -testcache;
5+
}
6+
7+
function test() {
8+
go test ./...;
9+
}
10+
11+
case $1 in
12+
clean) cleanTestCache;
13+
;;
14+
esac
15+
16+
test;

‎utils/infinite.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package utils
2+
3+
const (
4+
// MaxUint max unsigned int.
5+
MaxUint = ^uint(0)
6+
// MaxInt max int.
7+
MaxInt = int(MaxUint >> 1)
8+
9+
// MinUint min unsigned int.
10+
MinUint = 0
11+
12+
// MinInt min int
13+
MinInt = -MaxInt - 1
14+
)

‎utils/maxint.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package utils
2+
3+
// CalcMaxInt calc max int from multi nums.
4+
func CalcMaxInt(nums ...int) (res int) {
5+
// 此处也可使用堆排序,构建大顶堆,heapify之后直接取最大值.
6+
if len(nums) == 0 {
7+
return 0
8+
}
9+
10+
res = MinInt
11+
12+
for _, num := range nums {
13+
if num > res {
14+
res = num
15+
}
16+
}
17+
return
18+
}

‎utils/maxint_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package utils
2+
3+
import "testing"
4+
5+
func TestCalcMaxInt(t *testing.T) {
6+
testData := [][]int{
7+
{},
8+
{3, 4, 67, 8},
9+
}
10+
expectedData := []int{0, 67}
11+
12+
for index, data := range testData {
13+
if res := CalcMaxInt(data...); res != expectedData[index] {
14+
t.Errorf("expected %d, got %d", expectedData[index], res)
15+
}
16+
}
17+
}

‎utils/minint.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package utils
2+
3+
// CalcMinInt calc min int from multi nums.
4+
func CalcMinInt(nums ...int) (res int) {
5+
// 此处也可使用堆排序,构建小顶堆,heapify之后直接取最小值.
6+
if len(nums) == 0 {
7+
return 0
8+
}
9+
10+
res = MaxInt
11+
12+
for _, num := range nums {
13+
if num < res {
14+
res = num
15+
}
16+
}
17+
return
18+
}

‎utils/minint_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package utils
2+
3+
import "testing"
4+
5+
func TestCalcMinInt(t *testing.T) {
6+
testData := [][]int{
7+
{3, 4, 67, 8},
8+
{},
9+
}
10+
expectedData := []int{3, 0}
11+
12+
for index, data := range testData {
13+
if res := CalcMinInt(data...); res != expectedData[index] {
14+
t.Errorf("expected %d, got %d", expectedData[index], res)
15+
}
16+
}
17+
}

‎utils/set.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package utils
2+
3+
// Exists 空结构体
4+
var Exists = struct{}{}
5+
6+
// Set data structure implement by go.
7+
type Set map[interface{}]struct{}
8+
9+
// NewSet 初始化set
10+
func NewSet(items ...interface{}) Set {
11+
s := make(Set)
12+
s.Add(items...)
13+
return s
14+
}
15+
16+
// Add 向set中添加元素
17+
func (s Set) Add(items ...interface{}) error {
18+
for _, item := range items {
19+
s[item] = Exists
20+
}
21+
return nil
22+
}
23+
24+
// Contains 查看set中是否存在item
25+
func (s Set) Contains(item interface{}) bool {
26+
_, ok := s[item]
27+
return ok
28+
}
29+
30+
// Size 集合的大小
31+
func (s Set) Size() int {
32+
return len(s)
33+
}
34+
35+
// Clear 清空集合
36+
func (s Set) Clear() {
37+
s = make(Set)
38+
}
39+
40+
// Equal 判断两个set是否相等
41+
func (s Set) Equal(other Set) bool {
42+
if s.Size() != other.Size() {
43+
return false
44+
}
45+
for key := range s {
46+
if !other.Contains(key) {
47+
return false
48+
}
49+
}
50+
return true
51+
}
52+
53+
//IsSubset 判断s是否是other的子集
54+
func (s Set) IsSubset(other Set) bool {
55+
if s.Size() > other.Size() {
56+
return false
57+
}
58+
for key := range s {
59+
if !other.Contains(key) {
60+
return false
61+
}
62+
}
63+
return true
64+
}

0 commit comments

Comments
 (0)
Please sign in to comment.