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
36 changes: 36 additions & 0 deletions HigherOrderFunction/HOFF.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main


/*A higher order function that multilplies a number by itself
and then returns a function that returns the number divided by 2)
*/

func DoubleAndHalf(x int) func() int {

x = x * x

return func() int {

x = x / 2

return x
}
}


/*Another higher order function that halves a number and then
returns a function that returns the number multiplied by 3
*/

func HalfAndMultBy3(x int) func() int {

x = x / 2

return func() int {

x = x * 3

return x
}
}

25 changes: 25 additions & 0 deletions HigherOrderFunction/HOFF_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import ("testing")

/*
Purpose: To show that Golang is capable of producing
higher order functions and the typechecker can make sure
they are being used properly.
*/

// Test case that adds two values from the higher order functions

func TestSum(t *testing.T) {

x := DoubleAndHalf(5) //returns 12
y := HalfAndMultBy3(4) // returns 6

total := x() + y()

if total != 18 {

t.Errorf("Value is incorrect, got: %d, expected: %d.", total, 18)

}
}
9 changes: 9 additions & 0 deletions Plans.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
What Ive Done
- Learn basic Go
- Installed Go Tools
- Look through source code for examples

Plan to do
- Look at Go files relevant to my proposal
- Run tests on those files
-
18 changes: 18 additions & 0 deletions Syntax/syntax.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

//func max : Generates maximum between two numbers

func max(num1, num2 int) int {

var result int

if (num1 > num2) {

result = num1
} else {
result = num2
}

return result

}
46 changes: 46 additions & 0 deletions Syntax/syntax_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

//Purpose: to show that Golang will not execute invalid code
//and that the typechecker will reject ill-typed programs


import (
"testing"

)

//Test case works without any problems since syntax is correct

func TestMax(t *testing.T) {
if max(1,2) != 2 {
t.Error("Not 2")
}
}


//This test case won't work since the syntax for max 1,2 is not in the form max(1,2)

func TestMaxx(t *testing.T) {
if max 1,3 != 3 {
t.Error("Not 3")
}
}

/*
When gofmt -e syntax_test.go is ran the following occurs:
______________________________________________________

gofmt -e syntaxcorrect_test.go
syntaxcorrect_test.go:20:9: expected ';', found 1
syntaxcorrect_test.go:20:10: expected operand, found ','
syntaxcorrect_test.go:28:21: expected ';', found 'EOF'
syntaxcorrect_test.go:28:21: expected ';', found 'EOF'
syntaxcorrect_test.go:28:21: expected '{', found 'EOF'
syntaxcorrect_test.go:28:21: expected '}', found 'EOF'
syntaxcorrect_test.go:28:21: expected '}', found 'EOF'
________________________________________________________

If there are no syntax errrors the whole file will be displayed


*/
20 changes: 20 additions & 0 deletions Tests/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package errors implements functions to manipulate errors.
package errors

// New returns an error that formats as the given text.
func New(text string) error {
return &errorString{text}
}

// errorString is a trivial implementation of error.
type errorString struct {
s string
}

func (e *errorString) Error() string {
return e.s
}
53 changes: 53 additions & 0 deletions Tests/mytests_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package errors_test

import (
"errors"
"testing"
"fmt"

)


//Tests to see if allocated data in a variable is the same if data in variable
//are stored in another variable
func TestEquality(t *testing.T) {

text1:= errors.New("Hello")
text2 := text1

if text1 != text2 {
t.Errorf(`text1 != text2`)
}
}

//Tests to see if variable contains a value
func TestNotEmpty(t *testing.T){
text4 := errors.New("Something")
if text4 == nil{
t.Errorf(`"text4 is nil "`)
}
}

//Tests to see if error message will work
func TestErrorMessage(t *testing.T) {

message := errors.New("x and y are different values")

x := 2
y := 5
if x != y {
fmt.Print(message)
}


}










9 changes: 9 additions & 0 deletions ToDo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
What Ive Done
- Learn basic Go
- Installed Go Tools
- Look through source code for examples

Plan to do
- Look at Go files relevant to my proposal
- Run tests on those files
-
4 changes: 4 additions & 0 deletions Understanding.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
What I have done so far is to try and better understand the Go language and looking at examples of test cases to see how they were done.
I know just the basics of the Go language so viewing test cases and source code has led to me understanding the language more. Multiple
test cases in the folders makes it easier to see how test cases are done in this language.(Apparentley I pushed into another one of my repositories
by mistake).
6 changes: 6 additions & 0 deletions WhatILearnedSoFar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
To better understand the Go lanuage I decided to look through the documentation as well as the source code of the language.
What has helped is that there are various amounts of test cases and code that explains what its purpose is and what it is
suppose to do. One test case that has helped me is example_test.go. The purpose of it is to display the time and what the error
was when it occured. The reason it helped me understand the language better was because it shows how to create a function, import classes,
print messages, and return values. This may seem simple in another language but for someone who has barely ever used Go, it showed
me how to put things together.
44 changes: 44 additions & 0 deletions benchmark_Test/random.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (

//"fmt"
"time"
"math/rand"
"sort"
)

//sorts the numbers in an array
func performSort(size int){

//Seed to generate random numbers
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)

//makes list of a certain size
list := make([]int, size)


//Adds random values between 1 and 5000 into array
for i := 0; i < len(list); i++ {
list[i] = r1.Intn(5000)
}

//Prints the unsorted array
//fmt.Println("Unsorted",list)

//sorts the array
sort.Ints(list[:])

//Prints the sorted array
//fmt.Println("Sorted",list)


}







44 changes: 44 additions & 0 deletions benchmark_Test/random_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"testing"
)

//sorts array of 500 random values
func BenchmarkTest500(b *testing.B) {
performSort(500)
}

//sorts array of 1000 random values
func BenchmarkTest1000(b *testing.B) {
performSort(1000)
}

//sorts array of 500000 random values
func BenchmarkTest500000(b *testing.B) {
performSort(500000)
}

//sorts array of 1000000 random values
func BenchmarkTest1Mill(b *testing.B) {
performSort(1000000)
}

//sorts array of 500000000 random values
func BenchmarkTestFiveHundredMill(b *testing.B) {
performSort(500000000)
}

/*
$ go test -bench=.
goos: windows
goarch: amd64
BenchmarkTest500-4 2000000000 0.00 ns/op
BenchmarkTest1000-4 2000000000 0.00 ns/op
BenchmarkTest500000-4 1000000000 0.14 ns/op
BenchmarkTest1Mill-4 1000000000 0.24 ns/op
BenchmarkTestFiveHundredMill-4 1 157220687700 ns/op
PASS
ok 163.190s

*/
58 changes: 58 additions & 0 deletions mutation_analysis/HighOrderFunc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import("fmt")


/*A higher order function that multilplies a number by itself
and then returns a function that returns the number divided by 2)
*/

func DoubleAndHalf(x int) func() int {

x = x * x

return func() int {

x = x / 2

return x
}
}


/*Another higher order function that halves a number and then
returns a function that returns the number multiplied by 3
*/

func HalfAndMultBy3(x int) func() int {

x = x / 2

return func() int {

x = x * 3

return x
}
}

//Another way to perform a higher order function
func firstLastName(f func(string , string) string) string{

name := f("First","Last")

return name

}

func main(){

fullName := func(f_name string, l_name string) string{

return "My name is " + f_name + " " + l_name
}

fullString := firstLastName(fullName)

fmt.Println(fullString)
}
Loading