Skip to content

Commit cbaea08

Browse files
author
Aadit Kamat
authored
Add hello world exercism in go
1 parent c95cf7d commit cbaea08

File tree

7 files changed

+166
-0
lines changed

7 files changed

+166
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"blurb": "The classical introductory exercise. Just say \"Hello, World!\"",
3+
"authors": [
4+
"k4rtik"
5+
],
6+
"contributors": [
7+
"bitfield",
8+
"ekingery",
9+
"ferhatelmas",
10+
"hilary",
11+
"kytrinyx",
12+
"leenipper",
13+
"petertseng",
14+
"robphoenix",
15+
"SebastianKristof",
16+
"sebito91",
17+
"tleen"
18+
],
19+
"files": {
20+
"solution": [
21+
"hello_world.go"
22+
],
23+
"test": [
24+
"hello_world_test.go"
25+
],
26+
"example": [
27+
".meta/example.go"
28+
]
29+
},
30+
"source": "This is an exercise to introduce users to using Exercism",
31+
"source_url": "http://en.wikipedia.org/wiki/%22Hello,_world!%22_program"
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"track":"go","exercise":"hello-world","id":"1feef115cb0546caab11454f7ed1d686","url":"https://exercism.org/tracks/go/exercises/hello-world","handle":"aaditkamat","is_requester":true,"auto_approve":false}

Exercism/go/hello-world/HELP.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Help
2+
3+
## Running the tests
4+
5+
To run the tests run the command `go test` from within the exercise directory.
6+
7+
If the test suite contains benchmarks, you can run these with the `--bench` and `--benchmem`
8+
flags:
9+
10+
go test -v --bench . --benchmem
11+
12+
Keep in mind that each reviewer will run benchmarks on a different machine, with
13+
different specs, so the results from these benchmark tests may vary.
14+
15+
## Submitting your solution
16+
17+
You can submit your solution using the `exercism submit hello_world.go` command.
18+
This command will upload your solution to the Exercism website and print the solution page's URL.
19+
20+
It's possible to submit an incomplete solution which allows you to:
21+
22+
- See how others have completed the exercise
23+
- Request help from a mentor
24+
25+
## Need to get help?
26+
27+
If you'd like help solving the exercise, check the following pages:
28+
29+
- The [Go track's documentation](https://exercism.org/docs/tracks/go)
30+
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
31+
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
32+
33+
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
34+
35+
To get help if you're having trouble, you can use one of the following resources:
36+
37+
- [How to Write Go Code](https://golang.org/doc/code.html)
38+
- [Effective Go](https://golang.org/doc/effective_go.html)
39+
- [Go Resources](http://golang.org/help)
40+
- [StackOverflow](http://stackoverflow.com/questions/tagged/go)

Exercism/go/hello-world/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Hello World
2+
3+
Welcome to Hello World on Exercism's Go Track.
4+
If you need help running the tests or submitting your code, check out `HELP.md`.
5+
6+
## Instructions
7+
8+
The classical introductory exercise. Just say "Hello, World!".
9+
10+
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
11+
the traditional first program for beginning programming in a new language
12+
or environment.
13+
14+
The objectives are simple:
15+
16+
- Write a function that returns the string "Hello, World!".
17+
- Run the test suite and make sure that it succeeds.
18+
- Submit your solution and check it at the website.
19+
20+
If everything goes well, you will be ready to fetch your first real exercise.
21+
22+
## Source
23+
24+
### Created by
25+
26+
- @k4rtik
27+
28+
### Contributed to by
29+
30+
- @bitfield
31+
- @ekingery
32+
- @ferhatelmas
33+
- @hilary
34+
- @kytrinyx
35+
- @leenipper
36+
- @petertseng
37+
- @robphoenix
38+
- @SebastianKristof
39+
- @sebito91
40+
- @tleen
41+
42+
### Based on
43+
44+
This is an exercise to introduce users to using Exercism - http://en.wikipedia.org/wiki/%22Hello,_world!%22_program

Exercism/go/hello-world/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module greeting
2+
3+
go 1.16
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package greeting
2+
3+
// HelloWorld greets the world.
4+
func HelloWorld() string {
5+
return "Hello, World!"
6+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package greeting
2+
3+
import "testing"
4+
5+
// Define a function named HelloWorld that takes no arguments,
6+
// and returns a string.
7+
// In other words, define a function with the following signature:
8+
// HelloWorld() string
9+
10+
func TestHelloWorld(t *testing.T) {
11+
expected := "Hello, World!"
12+
if observed := HelloWorld(); observed != expected {
13+
t.Fatalf("HelloWorld() = %v, want %v", observed, expected)
14+
}
15+
}
16+
17+
// BenchmarkHelloWorld() is a benchmarking function. These functions follow the
18+
// form `func BenchmarkXxx(*testing.B)` and can be used to test the performance
19+
// of your implementation. They may not be present in every exercise, but when
20+
// they are you can run them by including the `-bench` flag with the `go test`
21+
// command, like so: `go test -v --bench . --benchmem`
22+
//
23+
// You will see output similar to the following:
24+
//
25+
// BenchmarkHelloWorld 2000000000 0.46 ns/op
26+
//
27+
// This means that the loop ran 2000000000 times at a speed of 0.46 ns per loop.
28+
//
29+
// While benchmarking can be useful to compare different iterations of the same
30+
// exercise, keep in mind that others will run the same benchmarks on different
31+
// machines, with different specs, so the results from these benchmark tests may
32+
// vary.
33+
func BenchmarkHelloWorld(b *testing.B) {
34+
if testing.Short() {
35+
b.Skip("skipping benchmark in short mode.")
36+
}
37+
for i := 0; i < b.N; i++ {
38+
HelloWorld()
39+
}
40+
}

0 commit comments

Comments
 (0)