Skip to content

Commit a114889

Browse files
committed
Corrección Roadmap 12 + Nuevo ejercicio 13
1 parent 806dd7a commit a114889

File tree

3 files changed

+135
-3
lines changed

3 files changed

+135
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
2828
## Corrección y próximo ejercicio
2929

30-
> #### Lunes 5 de Febrero de 2024 a las 20:00 (hora España) desde **[Twitch](https://twitch.tv/mouredev)**
31-
> #### Consulta el **[horario](https://discord.gg/YEU3gzfe?event=1201413529924796416)** por país y crea un **[recordatorio](https://discord.gg/YEU3gzfe?event=1201413529924796416)**
30+
> #### Lunes 1 de Abril de 2024 a las 20:00 (hora España) desde **[Twitch](https://twitch.tv/mouredev)**
31+
> #### Consulta el **[horario](https://discord.gg/xPGzfzbW?event=1219372916257456229)** por país y crea un **[recordatorio](https://discord.gg/xPGzfzbW?event=1219372916257456229)**
3232
3333
## Roadmap
3434

@@ -46,7 +46,8 @@
4646
|09|[HERENCIA Y POLIMORFISMO](./Roadmap/09%20-%20HERENCIA/ejercicio.md)|[📝](./Roadmap/09%20-%20HERENCIA/python/mouredev.py)|[▶️](https://youtu.be/PVBs5PWjedA)|[👥](./Roadmap/09%20-%20HERENCIA/)
4747
|10|[EXCEPCIONES](./Roadmap/10%20-%20EXCEPCIONES/ejercicio.md)|[📝](./Roadmap/10%20-%20EXCEPCIONES/python/mouredev.py)|[▶️](https://youtu.be/mfOzfj-BrQo)|[👥](./Roadmap/10%20-%20EXCEPCIONES/)
4848
|11|[MANEJO DE FICHEROS](./Roadmap/11%20-%20MANEJO%20DE%20FICHEROS/ejercicio.md)|[📝](./Roadmap/11%20-%20MANEJO%20DE%20FICHEROS/python/mouredev.py)|[▶️](https://youtu.be/Bsiay2nax4Y)|[👥](./Roadmap/11%20-%20MANEJO%20DE%20FICHEROS/)
49-
|12|[JSON Y XML](./Roadmap/12%20-%20JSON%20Y%20XML/ejercicio.md)|[🗓️ 25/03/24](https://discord.gg/NtSqCkZK?event=1216862528257130496)||[👥](./Roadmap/12%20-%20JSON%20Y%20XML/)
49+
|12|[JSON Y XML](./Roadmap/12%20-%20JSON%20Y%20XML/ejercicio.md)|[📝](./Roadmap/12%20-%20JSON%20Y%20XML/python/mouredev.py)||[👥](./Roadmap/12%20-%20JSON%20Y%20XML/)
50+
|13|[PRUEBAS UNITARIAS](./Roadmap/13%20-%20PRUEBAS%20UNITARIAS/ejercicio.md)|[🗓️ 01/04/24](https://discord.gg/xPGzfzbW?event=1219372916257456229)||[👥](./Roadmap/12%20-%20PRUEBAS%20UNITARIAS/)
5051

5152
## Instrucciones
5253

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import os
2+
import xml.etree.ElementTree as xml
3+
import json
4+
5+
data = {
6+
"name": "Brais Moure",
7+
"age": 36,
8+
"birth_date": "29-04-1987",
9+
"programming_languages": ["Python", "Kotlin", "Swift"]
10+
}
11+
12+
xml_file = "mouredev.xml"
13+
json_file = "mouredev.json"
14+
15+
"""
16+
Ejercicio
17+
"""
18+
19+
# XML
20+
21+
22+
def create_xml():
23+
24+
root = xml.Element("data")
25+
26+
for key, value in data.items():
27+
child = xml.SubElement(root, key)
28+
if isinstance(value, list):
29+
for item in value:
30+
xml.SubElement(child, "item").text = item
31+
else:
32+
child.text = str(value)
33+
34+
tree = xml.ElementTree(root)
35+
tree.write(xml_file)
36+
37+
38+
create_xml()
39+
40+
with open(xml_file, "r") as xml_data:
41+
print(xml_data.read())
42+
43+
os.remove(xml_file)
44+
45+
# JSON
46+
47+
48+
def create_json():
49+
with open(json_file, "w") as json_data:
50+
json.dump(data, json_data)
51+
52+
53+
create_json()
54+
55+
with open(json_file, "r") as json_data:
56+
print(json_data.read())
57+
58+
os.remove(json_file)
59+
60+
"""
61+
Extra
62+
"""
63+
64+
create_xml()
65+
create_json()
66+
67+
68+
class Data:
69+
70+
def __init__(self, name, age, birth_date, programming_languages) -> None:
71+
self.name = name
72+
self.age = age
73+
self.birth_date = birth_date
74+
self.programming_languages = programming_languages
75+
76+
77+
with open(xml_file, "r") as xml_data:
78+
79+
root = xml.fromstring(xml_data.read())
80+
name = root.find("name").text
81+
age = root.find("age").text
82+
birth_date = root.find("birth_date").text
83+
programming_languages = []
84+
for item in root.find("programming_languages"):
85+
programming_languages.append(item.text)
86+
87+
xml_class = Data(name, age, birth_date, programming_languages)
88+
print(xml_class.__dict__)
89+
90+
91+
with open(json_file, "r") as json_data:
92+
json_dict = json.load(json_data)
93+
json_class = Data(
94+
json_dict["name"],
95+
json_dict["age"],
96+
json_dict["birth_date"],
97+
json_dict["programming_languages"]
98+
)
99+
print(json_class.__dict__)
100+
101+
os.remove(xml_file)
102+
os.remove(json_file)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# #13 PRUEBAS UNITARIAS
2+
> #### Dificultad: Fácil | Publicación: 25/03/24 | Corrección: 01/04/24
3+
4+
## Ejercicio
5+
6+
```
7+
/*
8+
* EJERCICIO:
9+
* Crea una función que se encargue de sumar dos números y retornar
10+
* su resultado.
11+
* Crea un test, utilizando las herramientas de tu lenguaje, que sea
12+
* capaz de determinar si esa función se ejecuta correctamente.
13+
*
14+
* DIFICULTAD EXTRA (opcional):
15+
* Crea un diccionario con las siguientes claves y valores:
16+
* "name": "Tu nombre"
17+
* "age": "Tu edad"
18+
* "birth_date": "Tu fecha de nacimiento"
19+
* "programming_languages": ["Listado de lenguajes de programación"]
20+
* Crea dos test:
21+
* - Un primero que determine que existen todos los campos.
22+
* - Un segundo que determine que los datos introducidos son correctos.
23+
*/
24+
```
25+
#### Tienes toda la información extendida sobre el roadmap de retos de programación en **[retosdeprogramacion.com/roadmap](https://retosdeprogramacion.com/roadmap)**.
26+
27+
Sigue las **[instrucciones](../../README.md)**, consulta las correcciones y aporta la tuya propia utilizando el lenguaje de programación que quieras.
28+
29+
> Recuerda que cada semana se publica un nuevo ejercicio y se corrige el de la semana anterior en directo desde **[Twitch](https://twitch.tv/mouredev)**. Tienes el horario en la sección "eventos" del servidor de **[Discord](https://discord.gg/mouredev)**.

0 commit comments

Comments
 (0)