include nizhnyNovgorod contest
Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
This commit is contained in:
parent
0fa88e6ac8
commit
49e0584f93
3 changed files with 35 additions and 12 deletions
|
@ -18,6 +18,9 @@ How to participate:
|
|||
5. If CI tests will pass, your contribution will be merged.
|
||||
6. When PR is merged, you're awesome and can potentially win a prize.
|
||||
|
||||
**Update**: [Nizhny Novgorod](https://vk.com/golang_nizhny) community can also participate.
|
||||
Just use `nizhnyNovgorod: true` field when adding a `gopher` entry.
|
||||
|
||||
## How the winner is selected
|
||||
|
||||
We print winner after tests are finished.
|
||||
|
@ -30,7 +33,9 @@ Example (how "printed" winner may look like):
|
|||
|
||||
![](https://habrastorage.org/webt/kl/kk/k7/klkkk7zghbwmsuwefnaqxhyv3-y.jpeg)
|
||||
|
||||
Pull Requests are accepted until 23:59 of September 30 (Moscow time).
|
||||
Deadlines:
|
||||
* Kazan: 23:59 of September 30 (Moscow time)
|
||||
* Nizhny Novgorod: 23:59 of October 1 (Moscow time)
|
||||
|
||||
If there are less than 5 participants, we can't grant any gifts, therefore, invite your friends!
|
||||
|
||||
|
|
|
@ -31,6 +31,8 @@ var gophers = []gopher{
|
|||
post: "https://vk.com/bontequero?w=wall140207068_146",
|
||||
},
|
||||
|
||||
// Participants from Nizhny Novgorod (https://vk.com/golang_nizhny):
|
||||
|
||||
// Testers. Do not need to contain a valid URL in post,
|
||||
// but should use `tester: true` and can't win a prize.
|
||||
{
|
||||
|
@ -84,6 +86,10 @@ type gopher struct {
|
|||
|
||||
// tester can submit invalid post string, but can't win a prize.
|
||||
tester bool
|
||||
|
||||
// nizhnyNovgorod tells whether a participant is a part of Nizhny Novgorod
|
||||
// Go community.
|
||||
nizhnyNovgorod bool
|
||||
}
|
||||
|
||||
// key returns a hopefully unique participant key.
|
||||
|
|
|
@ -6,10 +6,19 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func runWinnerTest(t *testing.T, gophers []gopher) {
|
||||
if len(gophers) >= 5 {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
winner := rand.Intn(len(gophers))
|
||||
t.Logf("The winner is: %s!", gophers[winner].key())
|
||||
} else {
|
||||
t.Log("Not enough participants")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWinner(t *testing.T) {
|
||||
// filtered is a list of participating gophers.
|
||||
// Basically, a gophers list without ignored members.
|
||||
filtered := []gopher{}
|
||||
kazanGophers := []gopher{}
|
||||
nizhnyGophers := []gopher{}
|
||||
|
||||
// keys is a set of all participants keys.
|
||||
// Needed to detect collisions.
|
||||
|
@ -36,14 +45,17 @@ func TestWinner(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
filtered = append(filtered, g)
|
||||
if g.nizhnyNovgorod {
|
||||
nizhnyGophers = append(nizhnyGophers, g)
|
||||
} else {
|
||||
kazanGophers = append(kazanGophers, g)
|
||||
}
|
||||
}
|
||||
|
||||
if len(filtered) >= 5 {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
winner := rand.Intn(len(filtered))
|
||||
t.Logf("The winner is: %s!", filtered[winner].key())
|
||||
} else {
|
||||
t.Log("Not enough participants")
|
||||
}
|
||||
t.Run("Kazan", func(t *testing.T) {
|
||||
runWinnerTest(t, kazanGophers)
|
||||
})
|
||||
t.Run("NizhnyNovgorod", func(t *testing.T) {
|
||||
runWinnerTest(t, nizhnyGophers)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue