Skip to content

Commit

Permalink
Added additional tests and covered all parts of code (including panics)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsanjoseph committed Jan 14, 2022
1 parent 237fe79 commit ea31c3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
9 changes: 9 additions & 0 deletions riemann/counterexample_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ var _ = Describe("CounterExample Search", func() {
Expect(err).To(HaveOccurred())
})

It("should panic if asked to find witnesses for cases where DivisorSum cannot be found", func() {
Expect(func() { riemann.WitnessValue(-1, -1) }).To(PanicWith("Error calculating DivisorSum"))
})

It("should search successfully", func() {
output, err := riemann.Search(10000, 5040)
if err != nil {
Expand Down Expand Up @@ -59,4 +63,9 @@ var _ = Describe("CounterExample Search", func() {
}

})

It("Should panic if it can't compute riemann sums", func() {
Expect(func() { riemann.ComputerRiemannDivisorSums(0, 1) }).Should(PanicWith("Divisor Sum cannot be found"))

})
})
10 changes: 7 additions & 3 deletions riemann/populate_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ package riemann

import "fmt"

func PopulateDB(db DivisorDb, startingN, endingN, batchSize int64) {
func FindStartingNForDB(db DivisorDb, startingN int64) int64 {
var currentStartingN int64

dbStartingN := db.Summarize().LargestComputedN.N

if dbStartingN > startingN {
currentStartingN = dbStartingN
currentStartingN = dbStartingN + 1
} else {
currentStartingN = startingN
}
return currentStartingN
}

func PopulateDB(db DivisorDb, startingN, endingN, batchSize int64) {
currentStartingN := FindStartingNForDB(db, startingN)
currentEndingN := currentStartingN + batchSize

fmt.Println(dbStartingN, startingN, endingN, currentEndingN, currentStartingN)
for endingN == -1 || currentEndingN < endingN+batchSize {
db.Upsert(ComputerRiemannDivisorSums(currentStartingN, currentEndingN))
fmt.Printf("Computed Sums from %d to %d\n", currentStartingN, currentEndingN)
Expand Down
13 changes: 11 additions & 2 deletions riemann/populate_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ import (

var _ = Describe("Populates Database correctly", func() {

var db = riemann.DivisorDb(riemann.InMemoryDivisorDb{Data: make(map[int64]riemann.RiemannDivisorSum)})
It("Populates and Summarizes correctly", func() {
var db = riemann.DivisorDb(riemann.InMemoryDivisorDb{Data: make(map[int64]riemann.RiemannDivisorSum)})

riemann.PopulateDB(db, 10070, 10085, 21)
summaryData := db.Summarize()
Expect(summaryData.LargestWitnessValue.N).To(Equal(int64(10080)))
Expect(summaryData.LargestWitnessValue.N).To(BeEquivalentTo(10080))
Expect(summaryData.LargestComputedN.N).To(BeEquivalentTo(10091))
})

It("Finds startingN correctly", func() {

startingN := riemann.FindStartingNForDB(db, 10075)
Expect(startingN).To(BeEquivalentTo(10092))

})
})

0 comments on commit ea31c3f

Please sign in to comment.