Skip to content

Commit

Permalink
Refactor perlin2d and perlin3d test functions to use float64 tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Jan 6, 2024
1 parent 95f081f commit 36558fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions noise/perlin2d_test.v
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module noise

import math { abs }
import rand

const single_perlin = f64(0.4948387311305851)
import vsl.float.float64

fn test_perlin2d() {
rand.seed([u32(3155200429), u32(3208395956)])
mut gen := Perlin{}
gen.randomize()

assert abs(gen.perlin2d(0.125, 0.125) - noise.single_perlin) < 1.0e-6
result := gen.perlin2d(0.125, 0.125)
expected := 0.4948387311305851

assert float64.tolerance(result, expected, 1.0e-6)
}
9 changes: 5 additions & 4 deletions noise/perlin3d_test.v
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module noise

import math { abs }
import rand

const single_perlin_3d = f64(0.3713334855776509)
import vsl.float.float64

fn test_perlin3d() {
rand.seed([u32(3155200429), u32(3208395956)])
mut gen := Perlin{}
gen.randomize()

assert abs(gen.perlin3d(0.125, 0.125, 0.125) - noise.single_perlin_3d) < 1.0e-6
result := gen.perlin3d(0.125, 0.125, 0.125)
expected := 0.3713334855776509

assert float64.tolerance(result, expected, 1.0e-6)
}

0 comments on commit 36558fe

Please sign in to comment.