Browse Source

add unit testing

Chris Cromer 4 months ago
parent
commit
8d1e27bd96
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
5 changed files with 68 additions and 0 deletions
  1. 1
    0
      meson.build
  2. 20
    0
      test/meson.build
  3. 10
    0
      test/money.vala
  4. 11
    0
      test/percentage.vala
  5. 26
    0
      test/rut.vala

+ 1
- 0
meson.build View File

@@ -27,3 +27,4 @@ subdir('lib')
27 27
 subdir('src')
28 28
 subdir('doc')
29 29
 subdir('script')
30
+subdir('test')

+ 20
- 0
test/meson.build View File

@@ -0,0 +1,20 @@
1
+money_test = executable('money',
2
+	'money.vala',
3
+	dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, lib_dep],
4
+	install : false)
5
+
6
+test('Money', money_test)
7
+
8
+rut_test = executable('rut',
9
+	'rut.vala',
10
+	dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, lib_dep],
11
+	install : false)
12
+
13
+test('RUT', rut_test)
14
+
15
+percentage_test = executable('percentage',
16
+	'percentage.vala',
17
+	dependencies: [glib_dep, gobject_dep, gtk_dep, gmodule_dep, pq_dep, lib_dep],
18
+	install : false)
19
+
20
+test('Percentage', percentage_test)

+ 10
- 0
test/money.vala View File

@@ -0,0 +1,10 @@
1
+namespace SernaturTest {
2
+	using LibSernatur.Misc;
3
+
4
+	public static int main (string[] args) {
5
+		assert (Money.format_int (100000) == "$100.000");
6
+		assert (Money.format_uint (100000) == "$100.000");
7
+		assert (Money.format_string ("100000") == "$100.000");
8
+		return 0;
9
+	}
10
+}

+ 11
- 0
test/percentage.vala View File

@@ -0,0 +1,11 @@
1
+namespace SernaturTest {
2
+	using LibSernatur.Misc;
3
+
4
+	public static int main (string[] args) {
5
+		assert (Percentage.format_float ((float) 0.43) == "43%");
6
+		assert (Percentage.format_float ((float) 1) == "100%");
7
+		assert (Percentage.format_double (0.43) == "43%");
8
+		assert (Percentage.format_double (1) == "100%");
9
+		return 0;
10
+	}
11
+}

+ 26
- 0
test/rut.vala View File

@@ -0,0 +1,26 @@
1
+namespace SernaturTest {
2
+	using LibSernatur.Misc;
3
+
4
+	public static int main (string[] args) {
5
+		try {
6
+			Rut rut = new Rut ("18166316-2");
7
+			assert (rut.get_clean_rut () == "181663162");
8
+			assert (rut.get_rut () == "18.166.316-2");
9
+			assert (rut.type () == Rut.Type.RUN);
10
+
11
+			rut = new Rut ("20380508-k");
12
+			assert (rut.get_clean_rut () == "20380508K");
13
+			assert (rut.get_rut () == "20.380.508-K");
14
+			assert (rut.type () == Rut.Type.RUN);
15
+
16
+			rut = new Rut ("50380508-1");
17
+			assert (rut.get_clean_rut () == "503805081");
18
+			assert (rut.get_rut () == "50.380.508-1");
19
+			assert (rut.type () == Rut.Type.RUT);
20
+		}
21
+		catch (Error e) {
22
+			error (e.message);
23
+		}
24
+		return 0;
25
+	}
26
+}

Loading…
Cancel
Save