1
+ import Foundation
2
+
3
+
4
+ // FUNCION DE SUMA
5
+ print ( " \n FUNCION DE SUMA " )
6
+
7
+ func addTwoInts( addEnd1 n1: Int , addEnd2 n2: Int ) -> Int {
8
+ n1 + n2
9
+ }
10
+
11
+ func testAddTwoIntsFunction( ) {
12
+
13
+ let result1 = addTwoInts ( addEnd1: 2 , addEnd2: 2 ) == 4
14
+
15
+ assert ( result1, " El resultado deveria ser: 4 " )
16
+
17
+ print ( " Test de la funcion de suma pasado. " )
18
+ }
19
+ testAddTwoIntsFunction ( )
20
+
21
+
22
+
23
+
24
+ // DIFICULTAD EXTRA
25
+ print ( " \n DIFICULTAD EXTRA. " )
26
+
27
+ var dictionary : [ String : Any ] = [
28
+ " name " : " alberto " ,
29
+ " age " : 39 ,
30
+ " birthDate " : " 04/07/1984 " ,
31
+ " programmingLenguages " : [ " Swift " , " Python " , " Bash " ]
32
+ ]
33
+
34
+ func testDictionaryKeys( ) {
35
+
36
+ let nameChecker = dictionary. keys. contains ( " name " )
37
+ let ageChecker = dictionary. keys. contains ( " age " )
38
+ let birthDateChecker = dictionary. keys. contains ( " birthDate " )
39
+ let programmingLenguagesChecker = dictionary. keys. contains ( " programmingLenguages " )
40
+
41
+ assert ( nameChecker, " El campo name no existe. " )
42
+ assert ( ageChecker, " El campo age no existe. " )
43
+ assert ( birthDateChecker, " El campo birthDate no existe. " )
44
+ assert ( programmingLenguagesChecker, " El campo programmingLenguages no existe. " )
45
+
46
+ print ( " Test de campos del diccionario pasado. " )
47
+
48
+ }
49
+ testDictionaryKeys ( )
50
+
51
+ func testDictionaryValues( ) {
52
+
53
+ let nameValueChercker = dictionary [ " name " ] as? String == " alberto "
54
+ let ageValueChecker = dictionary [ " age " ] as? Int == 39
55
+ let birthDateValueChecker = dictionary [ " birthDate " ] as? String == " 04/07/1984 "
56
+ let programmingLenguagesValueChecker = dictionary [ " programmingLenguages " ] as? [ String ] == [ " Swift " , " Python " , " Bash " ]
57
+
58
+ assert ( nameValueChercker, " El valor de name no es alberto " )
59
+ assert ( ageValueChecker, " El valor de age no es 39 " )
60
+ assert ( birthDateValueChecker, " El valor de birthDate no es 04/07/1984 " )
61
+ assert ( programmingLenguagesValueChecker, " Los valores de programmingLenguages no es [Swift, Python, Bash] " )
62
+
63
+ print ( " Test del los valores del diccionario pasado. " )
64
+ }
65
+ testDictionaryValues ( )
0 commit comments