test.rs.html -- source
Description: Source to the Rust file `src\test.rs`.
Keywords: rust, rustlang, rust-lang

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69

    #[cfg(test)]
    mod tests {
      use Simplex;

      #[test]
      fn test_simplex() {
        let sn = Simplex::new();
        sn.noise_2d(0.0, 0.0);
      }

      #[test]
      fn test_from_seed() {
        let mut sn = Simplex::from_seed(vec![1, 2, 3]);
        let mut other_sn = Simplex::from_seed(vec![1, 2, 3]);

        assert_eq!(other_sn.noise_2d(1.0, 14.2), sn.noise_2d(1.0, 14.2));
        assert_eq!(other_sn.noise_3d(1.0, 14.2, -5.4), sn.noise_3d(1.0, 14.2, -5.4));

        sn = Simplex::from_seed(vec![4, 5, 6]);
        other_sn = Simplex::from_seed(vec![1, 2, 3]);

        assert!(other_sn.noise_2d(1.0, 14.2) != sn.noise_2d(1.0, 14.2));
        assert!(other_sn.noise_3d(1.0, 14.2, -5.4) != sn.noise_3d(1.0, 14.2, -5.4));
      }

      #[test]
      fn test_sum_octave_2d() {
        let sn = Simplex::new();
        let mut luminance = Vec::<Vec<f32>>::new();
        for x in 0..100 {
          luminance.push(Vec::<f32>::new());
          for y in 0..100 {
            luminance[x as usize].push(sn.sum_octave_2d(16, x as f32, y as f32, 0.5, 0.008));
          }
        }
      }

      #[test]
      fn test_sum_octave_3d() {
        let sn = Simplex::new();
        let mut luminance = Vec::<Vec<Vec<f32>>>::new();
        for x in 0..10 {
          luminance.push(Vec::<Vec<f32>>::new());
          for y in 0..10 {
            luminance[x as usize].push(Vec::<f32>::new());
            for z in 0..10 {
              luminance[x as usize][y as usize].push(sn.sum_octave_3d(16, x as f32, y as f32, z as f32, 0.5, 0.008));
            }
          }
        }
      }

      #[test]
      fn test_noise_2d() {
        let sn = Simplex::from_seed(vec![5, 3, 2, 1, 1]);
        assert_eq!(sn.noise_2d(1.5, -0.5), sn.noise_2d(1.5, -0.5));
        let other_sn = Simplex::from_seed(vec![0, 1, 2, 3, 4, 5]);
        assert!(sn.noise_2d(1.5, -0.5) != other_sn.noise_2d(1.5, -0.5));
      }

      #[test]
      fn test_noise_3d() {
        let sn = Simplex::from_seed(vec![5, 3, 2, 1, 1]);
        assert_eq!(sn.noise_3d(1.5, -0.5, 2.1), sn.noise_3d(1.5, -0.5, 2.1));
        let other_sn = Simplex::from_seed(vec![0, 1, 2, 3, 4, 5]);
        assert!(sn.noise_3d(1.5, -0.5, 2.1) != other_sn.noise_3d(1.5, -0.5, 2.1));
      }

    }

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result
+
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)