File: test_v_random.py

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (68 lines) | stat: -rw-r--r-- 2,228 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3
"""
Name:      v.random test
Purpose:   Tests v.random and its flags/options.
Authors:   Josef Pudil (original draft)
           Sunveer Singh (finished test)
Copyright: (C) 2020-2021 by Sunveer Singh and the GRASS Development Team
Licence:   This program is free software under the GNU General Public
           License (>=v2). Read the file COPYING that comes with GRASS
           for details.
"""
from grass.gunittest.case import TestCase
from grass.gunittest.main import test


class TestVRandom(TestCase):
    output = "test01"
    output2 = "test02"
    npoints = 100
    state = "nc_state"
    zmin = 10
    zmax = 120

    @classmethod
    def setUpClass(cls):
        cls.use_temp_region()
        cls.runModule("g.region", vector=cls.state)

    @classmethod
    def tearDownClass(cls):
        cls.del_temp_region()

    def tearDown(cls):
        cls.runModule("g.remove", type="vector", flags="f", name=cls.output)
        cls.runModule("g.remove", type="vector", flags="f", name=cls.output2)

    def test_num_points(self):
        """Checking if number of points equals 100"""
        self.assertModule("v.random", output=self.output, npoints=self.npoints)
        topology = dict(points=self.npoints)
        self.assertVectorFitsTopoInfo(vector=self.output, reference=topology)

    def test_num_points_3D(self):
        """Checking if the map is 3D and number of points is 100"""
        self.assertModule(
            "v.random",
            output=self.output,
            npoints=self.npoints,
            zmin=self.zmin,
            zmax=self.zmax,
            flags="z",
        )
        topology = dict(points=self.npoints, map3d=1)
        self.assertVectorFitsTopoInfo(vector=self.output, reference=topology)

    def test_restrict(self):
        """Checking if all points are in the polygon boundary state"""
        self.assertModule(
            "v.random", output=self.output, npoints=self.npoints, restrict=self.state
        )
        self.assertModule(
            "v.clip", input=self.output, clip=self.state, output=self.output2
        )
        self.assertVectorInfoEqualsVectorInfo(self.output, self.output2, precision=0.01)


if __name__ == "__main__":
    test()