File size: 968 Bytes
2afa69c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import sys
import os
sys.path.append(os.getcwd())

from engine.grid import WorldGrid
import numpy as np

def test_grid():
    print("Testing WorldGrid...")
    grid = WorldGrid(width=10, height=10, cell_size=10.0, sea_level=0.0)
    
    # Check initialization
    assert grid.elevation.shape == (10, 10)
    print("Initialization OK")
    
    # Check uplift
    grid.apply_uplift(1.0, dt=10.0)
    assert np.allclose(grid.bedrock, 10.0)
    assert np.allclose(grid.elevation, 10.0)
    print("Uplift OK")
    
    # Check sediment
    grid.add_sediment(np.full((10, 10), 5.0))
    assert np.allclose(grid.sediment, 5.0)
    assert np.allclose(grid.elevation, 15.0)  # 10 bedrock + 5 sediment
    print("Sediment OK")
    
    # Check gradient
    grid.elevation[0, 0] = 100.0  # High point
    slope, aspect = grid.get_gradient()
    print(f"Max Slope: {np.max(slope):.2f}")
    
    print("All WorldGrid tests passed!")

if __name__ == "__main__":
    test_grid()