-
Notifications
You must be signed in to change notification settings - Fork 13
Primitives #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
VidarHUN
wants to merge
5
commits into
master
Choose a base branch
from
primitives
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Primitives #3
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Numbers - Calculate the area of shapes | ||
|
|
||
| Write a small function with multiple input parameters and return the area of {{index . "shape"}}. The formula: {{index . "formula"}}. | ||
|
|
||
| Please be aware that you have to specify input parameters based on the given formula. Every parameter should be float64 and you have to return a float64 number. | ||
|
|
||
| In the file `exercise.go` near the placeholder `// INSERT YOUR CODE HERE`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package numbers | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| const r float64 = 3.4 | ||
| const a float64 = 3.6 | ||
| const b float64 = 4.2 | ||
| const h float64 = 6.9 | ||
|
|
||
|
|
||
| func TestArea(t *testing.T) { | ||
| switch "{{index . "shape"}}"{ | ||
| case "Circle": | ||
| assert.Equal(t, area(r, a, b, h), 36.32) | ||
| case "Ellipse": | ||
| assert.Equal(t, area(r, a, b, h), 47.5) | ||
| case "Trapezoid": | ||
| assert.Equal(t, area(r, a, b, h), 26.91) | ||
| case "Pentagon": | ||
| assert.Equal(t, area(r, a, b, h), 22.297) | ||
| case "Hexagon": | ||
| assert.Equal(t, area(r, a, b, h), 33.67) | ||
| case "Octagon": | ||
| assert.Equal(t, area(r, a, b, h), 62.58) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # PLEASE RUN make generate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package numbers | ||
|
|
||
| //go:generate go run ../../exercises-cli.go -student-id=$STUDENT_ID generate | ||
|
|
||
| // area will give back the area of the given shape. | ||
| func area(r, a, b, h float64) float64 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls template |
||
| // INSERT YOUR CODE HERE | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name: numbers | ||
| input: | ||
| - shape: "Circle" | ||
| formula: "A = pi * r^2" | ||
| - shape: "Ellipse" | ||
| formula: "A = a * b * pi" | ||
| - shape: "Trapezoid" | ||
| formula: "A = (a + b) * h / 2" | ||
| - shape: "Pentagon" | ||
| formula: "A = a^2 * sqrt{25 + 10sqrt{5}} / 4" | ||
| - shape: "Hexagon" | ||
| formula: "A = 3/2 * sqrt{3} * a^2" | ||
| - shape: "Octagon" | ||
| formula: "A = 2 * (1 + sqrt{2}) * a^2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // PLEASE RUN make generate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Strings - Change the network mask in the given CIDR address | ||
|
|
||
| Write a small function, and change the network mask of the {{index . "cidr"}} CIDR address to {{index . "subnet"}} in the file `exercise.go` near the placeholder `// INSERT YOUR CODE HERE`. Do not use additional variables, or modify the existing code. | ||
|
|
||
| Hint: Use strings.Split to split strings on an arbitrary delimiter. | ||
|
|
||
| CIDR notation is a compact representation of an IP address and its associated network mask. The notation was invented by Phil Karn in the 1980s. CIDR notation specifies an IP address, a slash ('/') character, and a decimal number. The decimal number is the count of consecutive leading 1-bits (from left to right) in the network mask. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package strings | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestReplaceNetMask(t *testing.T) { | ||
| assert.Equal(t, replaceNetMask("{{index . "cidr"}}", "{{index . "subnet"}}"), "{{index . "address"}}/{{index . "subnet"}}") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # PLEASE RUN make generate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package strings | ||
|
|
||
| //go:generate go run ../../exercises-cli.go -student-id=$STUDENT_ID generate | ||
|
|
||
| // replaceNetMask will replace the subnet part of a CIDR address | ||
| // Example -> 10.0.0.1/10 -> 10.0.0.1/14 | ||
| func replaceNetMask(address, newSubnet string) string { | ||
| // INSERT YOUR CODE HERE | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: "strings" | ||
| input: | ||
| - cidr: "192.168.1.1/24" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls make this a valid CIDR prefix. |
||
| address: "192.168.1.1" | ||
| subnet: "26" | ||
| - cidr: "10.0.0.138/12" | ||
| address: "10.0.0.138" | ||
| subnet: "24" | ||
| - cidr: "10.0.1.1/16" | ||
| address: "10.0.1.1" | ||
| subnet: "24" | ||
| - cidr: "192.168.254.254/24" | ||
| address: "192.168.254.254" | ||
| subnet: "32" | ||
| - cidr: "127.0.0.0/1" | ||
| address: "127.0.0.0" | ||
| subnet: "16" | ||
| - cidr: "152.66.115.203/32" | ||
| address: "152.66.115.203" | ||
| subnet: "32" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // PLEASE RUN make generate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please template