|
| 1 | +// DO NOT EDIT. |
| 2 | +// This file was generated automatically |
| 3 | +// from gen.go. Please do not edit this file. |
| 4 | + |
| 5 | +package md1 |
| 6 | + |
| 7 | +import ( |
| 8 | + "math/rand" |
| 9 | + "testing" |
| 10 | +) |
| 11 | + |
| 12 | +func Test_gridSubdomainInternal(t *testing.T) { |
| 13 | + rng := rand.New(rand.NewSource(1)) |
| 14 | + for i := 0; i < 100000; i++ { |
| 15 | + dmin := float64(rng.Float64()) |
| 16 | + dmax := dmin + float64(rng.Float64()) |
| 17 | + dsize := dmax - dmin |
| 18 | + |
| 19 | + smin := dmin + float64(rng.Float64())*dsize |
| 20 | + smaxsize := dmax - smin |
| 21 | + smax := smin + float64(rng.Float64())*smaxsize |
| 22 | + if i%8 == 0 { |
| 23 | + smax = dmax |
| 24 | + } |
| 25 | + if i%16 == 0 { |
| 26 | + smin = dmin |
| 27 | + } |
| 28 | + ssize := smax - smin |
| 29 | + for Nd := 2; Nd < 10; Nd++ { |
| 30 | + istart, nsub := GridSubdomain(dmin, dmax, Nd, smin, smax) |
| 31 | + if nsub > Nd { |
| 32 | + t.Error("subdomain contains more grid points than actual domain", nsub, Nd) |
| 33 | + } else if istart >= Nd { |
| 34 | + t.Error("istart >= Nd", istart, Nd) |
| 35 | + } else if istart+nsub > Nd { |
| 36 | + t.Error("istart+nsub>Nd", istart, nsub, istart+nsub, Nd) |
| 37 | + } else if nsub < 0 { |
| 38 | + t.Error("nsub<0", nsub) |
| 39 | + } |
| 40 | + dx := dsize / float64(Nd-1) |
| 41 | + calc_xmax := dmin + float64(istart+nsub-1)*dx |
| 42 | + calc_xmin := dmin + float64(istart)*dx |
| 43 | + if nsub > 0 && calc_xmax > smax { |
| 44 | + t.Error("xmax > smax", calc_xmax, smax) |
| 45 | + } |
| 46 | + if nsub > 0 && calc_xmin < smin { |
| 47 | + t.Error("xmin < smin", calc_xmin, smin) |
| 48 | + } |
| 49 | + if nsub > 0 && calc_xmax > dmax { |
| 50 | + t.Error("xmax > dmax", calc_xmax, dmax) |
| 51 | + } |
| 52 | + _ = ssize |
| 53 | + if t.Failed() { |
| 54 | + istart, nsub = GridSubdomain(dmin, dmax, Nd, smin, smax) // For debugging. |
| 55 | + t.Fatalf("failed on output: i=%d ns=%d input: d=(%.3f,%.3f) N=%d sub=(%.3f, %.3f) ix=%.3f", |
| 56 | + istart, nsub, dmin, dmax, Nd, smin, smax, calc_xmin) |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments