Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 02-primitives/01-numbers/.README.md
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`.
30 changes: 30 additions & 0 deletions 02-primitives/01-numbers/.exercise_test.go
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please template

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)
}
}
1 change: 1 addition & 0 deletions 02-primitives/01-numbers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PLEASE RUN make generate
8 changes: 8 additions & 0 deletions 02-primitives/01-numbers/exercise.go
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls template

// INSERT YOUR CODE HERE
}
14 changes: 14 additions & 0 deletions 02-primitives/01-numbers/exercise.yaml
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"
1 change: 1 addition & 0 deletions 02-primitives/01-numbers/exercise_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// PLEASE RUN make generate
7 changes: 7 additions & 0 deletions 02-primitives/02-strings/.README.md
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.
11 changes: 11 additions & 0 deletions 02-primitives/02-strings/.exercise_test.go
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"}}")
}
1 change: 1 addition & 0 deletions 02-primitives/02-strings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PLEASE RUN make generate
9 changes: 9 additions & 0 deletions 02-primitives/02-strings/exercise.go
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
}
20 changes: 20 additions & 0 deletions 02-primitives/02-strings/exercise.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "strings"
input:
- cidr: "192.168.1.1/24"
Copy link
Member

Choose a reason for hiding this comment

The 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"
1 change: 1 addition & 0 deletions 02-primitives/02-strings/exercise_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// PLEASE RUN make generate
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# exercise subdirs
EXERCISE_DIRS=\
01-getting-started \
02-primitives \
03-variables \
07-switch \
19-structs \
22-goroutines
Expand Down