-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IEnumerable增加Group、GroupBy 优化IEnumerable的Distinct、Enumerator、Index、Property、Select、Where
- Loading branch information
ahl5esoft
committed
Jun 18, 2019
1 parent
6f2dbcf
commit c25f30d
Showing
12 changed files
with
161 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,53 @@ | ||
package underscore | ||
|
||
import ( | ||
"testing" | ||
) | ||
import "testing" | ||
|
||
func Test_Group(t *testing.T) { | ||
dic := Group([]int{1, 2, 3, 4, 5}, func(n, _ int) string { | ||
if n%2 == 0 { | ||
return "even" | ||
} | ||
return "odd" | ||
}).(map[string][]int) | ||
if len(dic["even"]) != 2 { | ||
t.Error("wrong") | ||
func Benchmark_Group(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
dst := make([]int, 0) | ||
Range(1, benchmarkSize, 1).Group(func(n, _ int) string { | ||
if n%2 == 0 { | ||
return "even" | ||
} | ||
return "odd" | ||
}).Value(&dst) | ||
} | ||
} | ||
|
||
func Test_GroupBy(t *testing.T) { | ||
arr := []testModel{ | ||
{ID: 1, Name: "a"}, | ||
{ID: 2, Name: "a"}, | ||
{ID: 3, Name: "b"}, | ||
{ID: 4, Name: "b"}, | ||
} | ||
dic := GroupBy(arr, "name").(map[string][]testModel) | ||
if len(dic) != 2 { | ||
t.Error("wrong") | ||
func Benchmark_Group_New(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
dst := make([]int, 0) | ||
Range2(1, benchmarkSize, 1).Group(func(n, _ int) string { | ||
if n%2 == 0 { | ||
return "even" | ||
} | ||
return "odd" | ||
}).Value(&dst) | ||
} | ||
} | ||
|
||
func Test_Chain_Group(t *testing.T) { | ||
res := make(map[string][]int) | ||
Chain([]int{1, 2, 3, 4, 5}).Group(func(n, _ int) string { | ||
func Test_Group(t *testing.T) { | ||
dst := make(map[string][]int) | ||
Chain2([]int{1, 2, 3, 4, 5}).Group(func(n, _ int) string { | ||
if n%2 == 0 { | ||
return "even" | ||
} | ||
return "odd" | ||
}).Value(&res) | ||
if len(res["even"]) != 2 { | ||
}).Value(&dst) | ||
if len(dst["even"]) != 2 { | ||
t.Error("wrong") | ||
} | ||
} | ||
|
||
func Test_Chain_GroupBy(t *testing.T) { | ||
res := make(map[string][]testModel) | ||
Chain([]testModel{ | ||
func Test_GroupBy(t *testing.T) { | ||
dst := make(map[string][]testModel) | ||
Chain2([]testModel{ | ||
{ID: 1, Name: "a"}, | ||
{ID: 2, Name: "a"}, | ||
{ID: 3, Name: "b"}, | ||
{ID: 4, Name: "b"}, | ||
}).GroupBy("Name").Value(&res) | ||
if len(res) != 2 { | ||
}).GroupBy("Name").Value(&dst) | ||
if len(dst) != 2 { | ||
t.Error("wrong") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.