Skip to content

Commit 6732d25

Browse files
committed
Fixed #25
1 parent d551538 commit 6732d25

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121
- Code this function in the separate .go file inside a package and run tests. You may use anything you want except 3rd-party packages.
2222
- Create a PR with one .go file.
2323
- We will choose the most fast and elegant solution and merge into the repo within 7 days.
24+
25+
### How to create new challenge from template
26+
27+
```
28+
./new.sh challenge_name
29+
```

buildword/buildword.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package buildword
22

33
import (
4-
// "fmt"
54
"math"
65
"strconv"
76
)

new.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# Creates new package from template
3+
4+
set -e
5+
6+
# Package name
7+
pkg="$1"
8+
if [ -z "${pkg}" ]; then
9+
echo 'Error: Missing package name' 1>&2
10+
exit 1
11+
fi
12+
13+
if [ -d "${pkg}" ]; then
14+
echo 'Error: Challenge exists' 1>&2
15+
exit 1
16+
fi
17+
18+
cp -R template ${pkg}
19+
mv ${pkg}/template.go ${pkg}/${pkg}.go
20+
mv ${pkg}/template_test.go ${pkg}/${pkg}_test.go
21+
sed -i "" "s|template|$pkg|g" ${pkg}/${pkg}.go
22+
sed -i "" "s|template|$pkg|g" ${pkg}/${pkg}_test.go
23+
sed -i "" "s|template|$pkg|g" ${pkg}/README.md

template/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### template
2+
3+
### Example
4+
5+
### Run tests with benchmarks
6+
7+
```
8+
go test -bench .
9+
```

template/template.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package template
2+
3+
// Run func
4+
func Run() {}

template/template_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package template
2+
3+
import "testing"
4+
5+
func TestRun(t *testing.T) {}
6+
7+
func BenchmarkRun(b *testing.B) {
8+
for i := 0; i < b.N; i++ {
9+
Run()
10+
}
11+
}

0 commit comments

Comments
 (0)