diff --git a/go/hello-world/.exercism/config.json b/go/hello-world/.exercism/config.json new file mode 100644 index 0000000..a42a358 --- /dev/null +++ b/go/hello-world/.exercism/config.json @@ -0,0 +1,35 @@ +{ + "authors": [ + "k4rtik" + ], + "contributors": [ + "bitfield", + "ekingery", + "ferhatelmas", + "hilary", + "kytrinyx", + "leenipper", + "petertseng", + "robphoenix", + "SebastianKristof", + "sebito91", + "tleen" + ], + "files": { + "solution": [ + "hello_world.go" + ], + "test": [ + "hello_world_test.go" + ], + "example": [ + ".meta/example.go" + ], + "invalidator": [ + "go.mod" + ] + }, + "blurb": "The classical introductory exercise. Just say \"Hello, World!\".", + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/go/hello-world/.exercism/metadata.json b/go/hello-world/.exercism/metadata.json new file mode 100644 index 0000000..589a656 --- /dev/null +++ b/go/hello-world/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"go","exercise":"hello-world","id":"d4f5f27839e94f75a117c66838248852","url":"https://exercism.org/tracks/go/exercises/hello-world","handle":"negrienko","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/go/hello-world/HELP.md b/go/hello-world/HELP.md new file mode 100644 index 0000000..80bf78b --- /dev/null +++ b/go/hello-world/HELP.md @@ -0,0 +1,41 @@ +# Help + +## Running the tests + +To run the tests run the command `go test` from within the exercise directory. + +If the test suite contains benchmarks, you can run these with the `--bench` and `--benchmem` +flags: + + go test -v --bench . --benchmem + +Keep in mind that each reviewer will run benchmarks on a different machine, with +different specs, so the results from these benchmark tests may vary. + +## Submitting your solution + +You can submit your solution using the `exercism submit hello_world.go` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Go track's documentation](https://exercism.org/docs/tracks/go) +- The [Go track's programming category on the forum](https://forum.exercism.org/c/programming/go) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [How to Write Go Code](https://golang.org/doc/code.html) +- [Effective Go](https://golang.org/doc/effective_go.html) +- [Go Resources](http://golang.org/help) +- [StackOverflow](http://stackoverflow.com/questions/tagged/go) \ No newline at end of file diff --git a/go/hello-world/README.md b/go/hello-world/README.md new file mode 100644 index 0000000..cd3adf8 --- /dev/null +++ b/go/hello-world/README.md @@ -0,0 +1,45 @@ +# Hello World + +Welcome to Hello World on Exercism's Go Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +The classical introductory exercise. +Just say "Hello, World!". + +["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment. + +The objectives are simple: + +- Modify the provided code so that it produces the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +## Source + +### Created by + +- @k4rtik + +### Contributed to by + +- @bitfield +- @ekingery +- @ferhatelmas +- @hilary +- @kytrinyx +- @leenipper +- @petertseng +- @robphoenix +- @SebastianKristof +- @sebito91 +- @tleen + +### Based on + +This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file diff --git a/go/hello-world/go.mod b/go/hello-world/go.mod new file mode 100644 index 0000000..aecd42e --- /dev/null +++ b/go/hello-world/go.mod @@ -0,0 +1,3 @@ +module greeting + +go 1.18 diff --git a/go/hello-world/hello_world.go b/go/hello-world/hello_world.go new file mode 100644 index 0000000..28c166c --- /dev/null +++ b/go/hello-world/hello_world.go @@ -0,0 +1,6 @@ +package greeting + +// HelloWorld greets the world. +func HelloWorld() string { + return "Hello, World!" +} diff --git a/go/hello-world/hello_world_test.go b/go/hello-world/hello_world_test.go new file mode 100644 index 0000000..5e9c840 --- /dev/null +++ b/go/hello-world/hello_world_test.go @@ -0,0 +1,40 @@ +package greeting + +import "testing" + +// Define a function named HelloWorld that takes no arguments, +// and returns a string. +// In other words, define a function with the following signature: +// HelloWorld() string + +func TestHelloWorld(t *testing.T) { + expected := "Hello, World!" + if observed := HelloWorld(); observed != expected { + t.Fatalf("HelloWorld() = %v, want %v", observed, expected) + } +} + +// BenchmarkHelloWorld() is a benchmarking function. These functions follow the +// form `func BenchmarkXxx(*testing.B)` and can be used to test the performance +// of your implementation. They may not be present in every exercise, but when +// they are you can run them by including the `-bench` flag with the `go test` +// command, like so: `go test -v --bench . --benchmem` +// +// You will see output similar to the following: +// +// BenchmarkHelloWorld 2000000000 0.46 ns/op +// +// This means that the loop ran 2000000000 times at a speed of 0.46 ns per loop. +// +// While benchmarking can be useful to compare different iterations of the same +// exercise, keep in mind that others will run the same benchmarks on different +// machines, with different specs, so the results from these benchmark tests may +// vary. +func BenchmarkHelloWorld(b *testing.B) { + if testing.Short() { + b.Skip("skipping benchmark in short mode.") + } + for i := 0; i < b.N; i++ { + HelloWorld() + } +}