anz-bank / go-course Goto Github PK
View Code? Open in Web Editor NEWGo Programming Language Course
Home Page: https://go-course.org/
License: Apache License 2.0
Go Programming Language Course
Home Page: https://go-course.org/
License: Apache License 2.0
Implement function that produces Fibonacci sequence. Will produce for positive numbers only.
func letters(s string) map[rune]int
func sortLetters(m map[rune]int) []string
Call print(letters("aba")) in main to print:
a:2
b:1
Build lab 2 assignment code for Bubble and Insertion Sort for members of the slice.
func fib(n int)
1
1
2
3
5
8
13
Build lab 1 assignment code for Fibonacci and Negafibonacci series.
func fib(n int)
1
1
2
3
5
8
13
Create an executable go program that returns a sorted copy of int slice using bubble sort:
We want to encourage a basic understanding of testing in go works, which has been identified as a problem and is made worse by the reliance on rich third party libraries.
We want to start with the native testing
package that all tests must use, before introducing testify
that hides testing
behind a richer framework.
This repo has both Travis and Google Cloud Builds CI configurations, but there are some differences:
-race
when it runs the tests, cloudbuilds does not.-race
was not used on cloudbuilds because it would fail:
Step #1 - "test": Running: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
Step #1 - "test": # runtime/race
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::GetArgv()':
Step #1 - "test": gotsan.cc:(.text+0x4183): undefined reference to `__libc_stack_end'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::ReExec()':
Step #1 - "test": gotsan.cc:(.text+0x9797): undefined reference to `__libc_stack_end'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::InternalAlloc(unsigned long, __sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator32<__sanitizer::AP32> >*, unsigned long)':
Step #1 - "test": gotsan.cc:(.text+0xaac1): undefined reference to `__libc_malloc'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::InternalRealloc(void*, unsigned long, __sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator32<__sanitizer::AP32> >*)':
Step #1 - "test": gotsan.cc:(.text+0xca20): undefined reference to `__libc_realloc'
Step #1 - "test": race_linux_amd64.syso: In function `__sanitizer::InternalFree(void*, __sanitizer::SizeClassAllocatorLocalCache<__sanitizer::SizeClassAllocator32<__sanitizer::AP32> >*)':
Step #1 - "test": gotsan.cc:(.text+0x66e8): undefined reference to `__libc_free'
Step #1 - "test": collect2: error: ld returned 1 exit status
That is because the cloud-builder is an alpine image on which the race detector does not work because alpine is not glibc-based.
To make that work, we'll need to switch to a debian-based go cloud-builder.
Create an executable go program in directory 07_errors/USERNAME
Copy the CRUD puppy from upstream master 06_puppy/USERNAME
Add a custom error type Error with fields Message and Code
Extend the Storer interface for all methods to also return error
Create errors for:
- Value < 0
- ID not found in Read, Update and Delete
Add locking for proper use of sync.Map
Bonus points: Add a third Storer implementation using LevelDB
Lab 2 - Bubble sort
func bubble(s []int) []int
func Insertion(s []int) []int
func merge(s []int) []int
Lab 1 - Fibonacci sequence
Lab 1:
Provide solution for: https://github.com/anz-bank/go-course/tree/master/01_fib
This issue solves the fib number sequence, by calling fib(n) it will print the first n fib numbers line by line,
Build Fibonacci and bonus negafibonacci solution
It's usually preferable to decouple logic from other concerns like input & output, formatting. I.e. if a function has logic to compute something, it probably shouldn't also do IO.
Why? Decoupling things into components or layers that each have fewer responsibilities usually produces code that is simpler and more re-usable.
In this case: better that the function that computes fibonacci sequence is NOT responsible for doing IO (formatting the numbers to an output stream).
For example, code to compute fibonacci sequence that also writes strings to some global variable is less likely to be usable or re-usable when compared to code that simply returns the computed sequence as a new value in some "natural" representation such as a slice of integers. If you want, you can then call some other function to format the sequence to a string, but perhaps some times you don't want to format anything to a string!
Other things that you might want to do with a fibonacci sequence:
1 1 2 3 5 8 13 ... --> 0 1 2 4 7 12 20 33 ...
)It's much easier to do this if the sequence is represented as an array or slice of numbers, instead of as a formatted string!
Create an executable go program in directory 06_puppy/USERNAME
Implement a Puppy struct containing ID, Breed, Colour, Value
Create Storer interface with CRUD methods for Puppy
Write a MapStore implementation of Storer backed by a map
Write a SyncStore implementation of Storer backed by a sync.Map
Find hints at anz-bank/go-samplerest
Write tests against the Storer interface in a suite and run the suite with both implementations
J. D. Frazer "Illiad", User Friendly - Crud Puppy
03_letters/CameronSchafer
func letters(s string) map[rune]int
Write a function that returns a sorted slice of strings with elements "{key}:{val}"
. Use package sort:
func sortLetters(m map[rune]int) []string
Call fmt.Println(strings.Join(sortLetters(letters("aba")), "\n"))
in main
to print:
a:2
b:1
Bonus points: comprehensive tests
Create an executable go program that takes a string as the input and returns a mapping of each letter to its frequency.
Create an executable go program in directory 02_bubble/brvishnu92.
Write function that returns a sorted copy of int slice s using bubble sort.
Write test cases covering all function runs.
Create an executable go program in directory 05_stringer/USERNAME
Make the IPAddr type implement fmt.Stringer to print the address as a dotted quad
Find hints at Tour of Go Exercise: Stringers
Call fmt.Println(IPAddr{127, 0, 0, 1}) in main to print:
127.0.0.1
This issue optimizes the iteration logic for generating fib sequences and uses tables for unit tests
Lab 2
func numeronyms(vals ...string) []string
[a11y K8s abc]
Create directory 09_json/USERNAME containing a copy of upstream master
08_project/USERNAME
Add JSON tags to puppy data type
Test marshalling and unmarshalling using require.JSONEq
Add command line flag -d FILE with long form --data FILE using kingpin.v2. FILE should contain an array of puppies in JSON format. Parse this file and store its contents.
func letters(s string) map[rune]int
func sortLetters(m map[rune]int) []string
Call print(letters("aba")) in main to print:
a:2
b:1
Lab 2 - Bubble sort
func bubble(s []int) []int
Lab 1 - Fibonacci sequence
func fib(n int)
1
1
2
3
5
8
13
Create an executable go program that returns a slice of numeronyms for input strings.
The description in README file:
fmt.Println(strings.Join(sortLetters(letters("aba"))), "\n")
is supposed to be
fmt.Println(strings.Join(sortLetters(letters("aba")), "\n"))
We recommend using go 1.12 in our docs for the course, but the CI tools (travis and golangci-lint) are both using go 1.11. Update the configs to use newer versions.
Travis can be configured to use go 1.12.x
and golangci-lint can be updated to version v1.16.0 which contains go 1.12.
├── README.md
├── go.mod
├── go.sum
├── pkg
│ └── USERNAME-puppy
│ ├── types.go
│ ├── types_test.go
│ ├── errors.go
│ ├── errors_test.go
│ └── store
│ ├── storer.go
│ └── .... store files and tests, e.g. mapstore.go
├── cmd
│ └── USERNAME-puppy-server
│ └── main.go
└── vendor
Create an executable go program in directory 01_fib/brvishnu92.
Write a function that prints the first n Fibonacci numbers.
Write test cases covering all function runs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.