Skip to content

Commit 294bcab

Browse files
committed
Added a new module called create an executable file & added a readme which has the steps to create and run the executable in it
1 parent 084c31f commit 294bcab

File tree

7 files changed

+135
-1
lines changed

7 files changed

+135
-1
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ This consists of all the codes in the golang tutorial -> <https://go.dev/doc/tut
1010
* Step 3: Create a go module by creating a new file `[fileName].go`
1111
* Step 4: Write some basic go code in it and to run it type `go run .` or `go run <fileName>`
1212

13-
* [TBD]
13+
* Important go commands
14+
* `go mod init`
15+
* `go mod edit`
16+
* `go run`
17+
* `go test`
18+
* `go build`
19+
* `go install`
20+
21+
* Continued...

create_an_executable_file/Readme.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## How to create an executable file
2+
3+
1. Go to the main package of your project
4+
2. execute this command in your cmd: `go build`
5+
3. You will see that an executable file is created `[filename].exe`
6+
4. This executable file can be run on your local directory, but to run it as a path command from your command line anywhere please follow these steps
7+
1. Type `go list -f '{{.Target}}'` to get the target location of the executable file
8+
2. Follow the steps in the documentation to proceed furthur: https://go.dev/doc/tutorial/compile-install
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module aniket-batabyal.com/mathematicalOperations
2+
3+
go 1.20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package mathematicalOperations
2+
3+
import (
4+
"errors"
5+
)
6+
7+
func Summation(numbers []rune) rune {
8+
var sum rune = 0
9+
for _, val := range numbers {
10+
sum += val
11+
}
12+
13+
return sum
14+
}
15+
16+
func Multiplication(numbers []int) (int, error) {
17+
var multipliedSoFar int = 1
18+
19+
for _, num := range numbers {
20+
21+
if num < 1 {
22+
return 0, errors.New("numbers to be multiplied should be greater than 0")
23+
}
24+
25+
multipliedSoFar *= num
26+
}
27+
28+
return multipliedSoFar, nil
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package mathematicalOperations
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestSummationNumbers(t *testing.T) {
8+
9+
var valuesToSum []rune = []rune{
10+
1,
11+
2,
12+
3,
13+
4,
14+
5,
15+
}
16+
17+
want := 15
18+
summation := Summation(valuesToSum)
19+
20+
if rune(want) != summation {
21+
t.Fatalf("The summation values was not the expected result that we wanted")
22+
}
23+
}
24+
25+
func TestMultiplicationNonZeroNumbers(t *testing.T) {
26+
var numbersToMultiply []int = []int{
27+
1,
28+
2,
29+
3,
30+
4,
31+
5,
32+
}
33+
34+
want := 120
35+
36+
multiplicationValue, error := Multiplication(numbersToMultiply)
37+
38+
if error != nil && want != multiplicationValue {
39+
t.Fatal(error)
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module aniket-batabyal.com/mathematician
2+
3+
go 1.20
4+
5+
replace aniket-batabyal.com/mathematicalOperations => ../mathematicalOperations
6+
7+
require aniket-batabyal.com/mathematicalOperations v0.0.0-00010101000000-000000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"aniket-batabyal.com/mathematicalOperations"
8+
)
9+
10+
func main() {
11+
12+
var numbersToSum []rune = []rune{
13+
1,
14+
2,
15+
3,
16+
4,
17+
5,
18+
}
19+
20+
var numbersToMultiply []int = []int{
21+
10,
22+
20,
23+
30,
24+
40,
25+
1,
26+
10,
27+
}
28+
29+
multipliedValues, error := mathematicalOperations.Multiplication(numbersToMultiply)
30+
31+
if error != nil {
32+
log.Fatal(error)
33+
}
34+
35+
fmt.Println("The summation result: ", mathematicalOperations.Summation(numbersToSum))
36+
fmt.Println("The multiplication result: ", multipliedValues)
37+
}

0 commit comments

Comments
 (0)