From 89dcea1a6050eb96b30adf0a753b1e3f2d07b367 Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Wed, 26 Sep 2018 18:55:20 -0700 Subject: [PATCH 01/13] Understanding --- Understanding.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Understanding.txt diff --git a/Understanding.txt b/Understanding.txt new file mode 100644 index 00000000000000..de05a8b425f9e3 --- /dev/null +++ b/Understanding.txt @@ -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 never pushed into another one of my repositories +by mistake). \ No newline at end of file From e2caae11e10674fdf76b0b00af2c6a3d086b3d1d Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Wed, 26 Sep 2018 19:12:42 -0700 Subject: [PATCH 02/13] Corrections --- Understanding.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Understanding.txt b/Understanding.txt index de05a8b425f9e3..fb42c76b3acfc5 100644 --- a/Understanding.txt +++ b/Understanding.txt @@ -1,4 +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 never pushed into another one of my repositories +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). \ No newline at end of file From 4367e156bbf2883e4a9dcbb4dec1cf217730861b Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Thu, 27 Sep 2018 13:38:32 -0700 Subject: [PATCH 03/13] What I Learned So Far --- WhatILearnedSoFar.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 WhatILearnedSoFar.txt diff --git a/WhatILearnedSoFar.txt b/WhatILearnedSoFar.txt new file mode 100644 index 00000000000000..1b220be0da494f --- /dev/null +++ b/WhatILearnedSoFar.txt @@ -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. \ No newline at end of file From bfe7e7802755647989927fbf9e2563a25e692595 Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Wed, 3 Oct 2018 20:53:56 -0700 Subject: [PATCH 04/13] Plans --- Plans.txt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Plans.txt diff --git a/Plans.txt b/Plans.txt new file mode 100644 index 00000000000000..21ba0d70d1bd26 --- /dev/null +++ b/Plans.txt @@ -0,0 +1,8 @@ +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 \ No newline at end of file From 81985d3cdee34007d6aa22609d1d38e75857a958 Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Wed, 3 Oct 2018 21:19:27 -0700 Subject: [PATCH 05/13] New --- Plans.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plans.txt b/Plans.txt index 21ba0d70d1bd26..fd64b456371ef5 100644 --- a/Plans.txt +++ b/Plans.txt @@ -5,4 +5,5 @@ What Ive Done Plan to do - Look at Go files relevant to my proposal -- Run tests on those files \ No newline at end of file +- Run tests on those files +- \ No newline at end of file From 29159f8626ae869376954c70eda371d8c2c721e0 Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Wed, 3 Oct 2018 21:28:15 -0700 Subject: [PATCH 06/13] ToDo --- ToDo.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ToDo.txt diff --git a/ToDo.txt b/ToDo.txt new file mode 100644 index 00000000000000..fd64b456371ef5 --- /dev/null +++ b/ToDo.txt @@ -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 +- \ No newline at end of file From 23095569da8d7d80acd47bd21ca05f111145549e Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Wed, 17 Oct 2018 21:11:40 -0700 Subject: [PATCH 07/13] TestCase --- Tests/errors.go | 20 ++++++++++++++++ Tests/mytests_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Tests/errors.go create mode 100644 Tests/mytests_test.go diff --git a/Tests/errors.go b/Tests/errors.go new file mode 100644 index 00000000000000..e0c847c47b0122 --- /dev/null +++ b/Tests/errors.go @@ -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 +} diff --git a/Tests/mytests_test.go b/Tests/mytests_test.go new file mode 100644 index 00000000000000..413d682406ab35 --- /dev/null +++ b/Tests/mytests_test.go @@ -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) + } + + + } + + + + + + + + + + From 76c8b2664e9da424c2d8b5e163871be09cb3a460 Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Tue, 23 Oct 2018 16:23:43 -0700 Subject: [PATCH 08/13] Testing speed of the Go language --- random_test/random.go | 45 +++++++++++++++++++++++++++++++++++++ random_test/random_test.go | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 random_test/random.go create mode 100644 random_test/random_test.go diff --git a/random_test/random.go b/random_test/random.go new file mode 100644 index 00000000000000..461ab7b264c14d --- /dev/null +++ b/random_test/random.go @@ -0,0 +1,45 @@ +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) + + +} + + + + + + + diff --git a/random_test/random_test.go b/random_test/random_test.go new file mode 100644 index 00000000000000..930399c310fbec --- /dev/null +++ b/random_test/random_test.go @@ -0,0 +1,46 @@ +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 + +*/ \ No newline at end of file From 395e582f4948fbc787ea9b1745010fcfae39e273 Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Tue, 23 Oct 2018 16:37:21 -0700 Subject: [PATCH 09/13] Benchmark --- random_test/random.go | 1 - random_test/random_test.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/random_test/random.go b/random_test/random.go index 461ab7b264c14d..90aaa50e9c7422 100644 --- a/random_test/random.go +++ b/random_test/random.go @@ -30,7 +30,6 @@ func performSort(size int){ //sorts the array sort.Ints(list[:]) - //Prints the sorted array //fmt.Println("Sorted",list) diff --git a/random_test/random_test.go b/random_test/random_test.go index 930399c310fbec..0e9934ac8e58ed 100644 --- a/random_test/random_test.go +++ b/random_test/random_test.go @@ -1,9 +1,7 @@ package main import ( - "testing" - ) //sorts array of 500 random values From 5455873d436fa258b8ebe3ea781832aada92e972 Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Tue, 23 Oct 2018 16:43:43 -0700 Subject: [PATCH 10/13] Test Speed of language --- benchmark_Test/random.go | 44 +++++++++++++++++++++++++++++++++++ benchmark_Test/random_test.go | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 benchmark_Test/random.go create mode 100644 benchmark_Test/random_test.go diff --git a/benchmark_Test/random.go b/benchmark_Test/random.go new file mode 100644 index 00000000000000..90aaa50e9c7422 --- /dev/null +++ b/benchmark_Test/random.go @@ -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) + + +} + + + + + + + diff --git a/benchmark_Test/random_test.go b/benchmark_Test/random_test.go new file mode 100644 index 00000000000000..0e9934ac8e58ed --- /dev/null +++ b/benchmark_Test/random_test.go @@ -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 + +*/ \ No newline at end of file From 42cd8f788cdb2766990658d445f37dc3bed58adc Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Tue, 30 Oct 2018 21:27:29 -0700 Subject: [PATCH 11/13] Syntax Test --- Syntax/syntax.go | 18 +++++++++++++++++ Syntax/syntax_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Syntax/syntax.go create mode 100644 Syntax/syntax_test.go diff --git a/Syntax/syntax.go b/Syntax/syntax.go new file mode 100644 index 00000000000000..222963c27b9393 --- /dev/null +++ b/Syntax/syntax.go @@ -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 + + } \ No newline at end of file diff --git a/Syntax/syntax_test.go b/Syntax/syntax_test.go new file mode 100644 index 00000000000000..1c523f2d7625a7 --- /dev/null +++ b/Syntax/syntax_test.go @@ -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 + + +*/ \ No newline at end of file From c51353555a80bf08a710705f2d4d312f6044ef2b Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Tue, 6 Nov 2018 16:30:31 -0800 Subject: [PATCH 12/13] Higher Order Functions --- HigherOrderFunction/HOFF.go | 36 ++++++++++++++++++++++++++++++++ HigherOrderFunction/HOFF_test.go | 25 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 HigherOrderFunction/HOFF.go create mode 100644 HigherOrderFunction/HOFF_test.go diff --git a/HigherOrderFunction/HOFF.go b/HigherOrderFunction/HOFF.go new file mode 100644 index 00000000000000..61bdb966993f5b --- /dev/null +++ b/HigherOrderFunction/HOFF.go @@ -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 + } + } + diff --git a/HigherOrderFunction/HOFF_test.go b/HigherOrderFunction/HOFF_test.go new file mode 100644 index 00000000000000..ea7ccbb15d7df6 --- /dev/null +++ b/HigherOrderFunction/HOFF_test.go @@ -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) + + } + } \ No newline at end of file From 41435c9e0838f96f65aec8142cf65119e0207fdb Mon Sep 17 00:00:00 2001 From: Alex Melendez Date: Tue, 27 Nov 2018 16:24:46 -0800 Subject: [PATCH 13/13] Start of mutation tests --- mutation_analysis/HighOrderFunc.go | 58 ++++++++++++++++++++++++++ mutation_analysis/HighOrderFuncTest.go | 42 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 mutation_analysis/HighOrderFunc.go create mode 100644 mutation_analysis/HighOrderFuncTest.go diff --git a/mutation_analysis/HighOrderFunc.go b/mutation_analysis/HighOrderFunc.go new file mode 100644 index 00000000000000..a1fbc45386b863 --- /dev/null +++ b/mutation_analysis/HighOrderFunc.go @@ -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) + } \ No newline at end of file diff --git a/mutation_analysis/HighOrderFuncTest.go b/mutation_analysis/HighOrderFuncTest.go new file mode 100644 index 00000000000000..914d64d8986e46 --- /dev/null +++ b/mutation_analysis/HighOrderFuncTest.go @@ -0,0 +1,42 @@ +package main + +//import ("testing") + + +// manbearpig cannot run mutation tests on Go test files so the only way to get it to perform +// an analysis was to comment out the test features of the file such as import "testing" and +// t *testing.T used in the 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) + + } + } + + + + func TestName( /* t *testing.T */ ) { + + tempName := "My name is First Last" + + fullName := func(f_name string, l_name string) string{ + + return "My name is " + f_name + " " + l_name + } + + check := firstLastName(fullName) + + if check != tempName { + t.Errorf("Strings do not match.") + } + + } \ No newline at end of file