Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jacomago committed Mar 4, 2014
0 parents commit 7c90981
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
61 changes: 61 additions & 0 deletions data/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package data

import (
"bufio"
"math"
"os"
"strconv"
)

type Zeros map[float64]float64

func check(e error) {
if e != nil {
panic(e)
}
}

func ImportZeros(filename string) Zeros {
f, err := os.Open(filename)
check(err)

z := make(Zeros)
scanner := bufio.NewScanner(f)
for scanner.Scan() {
text := scanner.Text()
number, parseErr := strconv.ParseFloat(text, 64)
z[number] = number - math.Floor(number)
check(parseErr)
}
check(scanner.Err())
return z
}

func ExportData(data) {
}

func floatsEqual(a float64, b float64) bool {
Epsilon := 0.000001
if math.Abs(a-b) < Epsilon {
return true
}
return false
}

// fractional differences
func closestZero(z Zeros, zero float64) float64 {
}

func fractionalDifferences(z Zeros) (float64, float64) {
}

// zeros epsilon close to other
func fCloseTo(z Zeros, zero float64, epsilon float64) int {
}

func zerosFCloseTo(z Zeros, epsilon float64) float64 {
}

// histogram creating
func createHistogram(z Zeros, epsilon float64) map[int]float64 {
}
48 changes: 48 additions & 0 deletions data/data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package data

import (
"testing"
)

func TestFloatsEqual(t *testing.T) {
const inA, inB, out = 1.2, 1.2, true
if x := floatsEqual(inA, inB); x != out {
t.Errorf("floatsEqual(%v, %v) = %v, want %v", inA, inB, x, out)
}

const inA2, inB2, out2 = 1.2, 1.3, false
if x := floatsEqual(inA2, inB2); x != out2 {
t.Errorf("floatsEqual(%v, %v) = %v, want %v", inA2, inB2, x, out2)
}
}

func TestImportZeros(t *testing.T) {
const in string = "test.dat"
out := Zeros{3.14: 0.14, 2.71: 0.71}
x := ImportZeros(in)
for k, v := range x {
if !floatsEqual(out[k], v) {
t.Errorf("ImportZeros(%v) = %v, want %v", in, x, out)
}
}
}

func TestClosestZero(t *testing.T) {

}

func TestFractionalDifferences(t *testing.T) {

}

func TestFCloseTo(t *testing.T) {

}

func TestZerosFCloseTo(t *testing.T) {

}

func TestCreateHistogram(t *testing.T) {

}
2 changes: 2 additions & 0 deletions data/test.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
3.14
2.71
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main

func main() {
z := data.ImportZeros("zeros6")

}

0 comments on commit 7c90981

Please sign in to comment.