This is an exercise to practice TDD focusing on the selection of examples. The nature of the problem adds some difficult to choose the right examples. This happens because several separation rules can be applied to the same word. This can require more than one reason for a test to fail.
The goal of the exercise is to help you to develop a sense for identifying good examples for making new tests which can fail for a unique reason.
Imagine that you are working in some text visualization tool that requires hyphenation. To achieve that, you will need and algorithm to separate Spanish words into syllables.
Spanish language has a bunch of rules for separating a word into Syllables. They are described in different ways depending on the source of information. We decided to use the following, adapted from this document by Instituto Cervantes
A consonant and the following vowel are pronounced in the same syllable, for example:
ma–ra-ca
ti–je-ra
Remember that the letter h
is not pronounced except when combined with the letter c
to form ch
. Keep in mind that ch
, ll
, and rr
, although written as two letters each (hence called "digraphs"), are pronounced as a single sound each, and this is what counts when dividing syllables, for example:
chi-llar
cho-rro
When two consonants are found between two vowels, the first generally forms a syllable with the preceding vowel and the second forms a syllable with the following vowel, for example:
cam-po
sal-to
har-to
an-da
When three consonants are found between two vowels, the first two generally form a syllable with the preceding vowel, and the third forms a syllable with the following vowel, for example:
ins-ta
obs-ti-na-do
su-pers-ti-ción
The following consonant pairs (consonant groups) are normally pronounced as a single syllable: bl, br, cl, cr, dr, fl, fr, gl, kl, gr, pl, pr, tr
. Examples:
ha-blar
te-cla
sa-cro
si-glo
ma-dre
de-trás
a-grio
hom-bre
in-flar
san-gre
du-pli-ca-do
com-pren-der
en-trar
When four consonants are found between two vowels, the first two form a syllable with the preceding vowel, and the last two form a syllable with the following vowel, for example:
cons-truir
trans–plan-te
abs-trac-to
obs-truir
When an i
or a u
are next to another vowel, they are usually pronounced as a single syllable, for example:
hay
fui
pues
cual
When two vowels come together, but neither of them is i
nor u
, they are usually pronounced in a different syllable, for example:
a-é-re-o
O-es-te
bo-a
Bil-ba-o
For starting, we suggest to forgot about tildes and capitalized words.
Fran Iglesias: https://github.com/franiglesias/cutwords
Configuración básica para empezar a hacer una kata o aprender a hacer tests en los siguientes lenguajes:
- PHP con PHPUnit
- Javascript con Jest
- Typescript con Node
- Typescript con Deno
- Java con Junit y Mockito
- Scala con Munit y Scalacheck
- Kotlin con JUnit5 y MockK
- C# con xUnit (FluentAsertion) y NSubstitute (para mock)
- Go con testing (standard library)
- Instalar composer
curl -sS https://getcomposer.org/installer | php
composer install
(estando en la carpeta php)vendor/bin/phpunit
ocomposer test
- Instalar Node
npm install
(Estando en la carpeta javascript)npm test
- Instalar Deno
deno test
(Estando en la carpeta typescript)
- Instalar las dependencias y tests con Maven [mvn test]
- Ejecutar los tests con el IDE
sbt
(en la carpeta scala)~test
para ejecutar los test en hot reload
- Munit
- Scalacheck para testing basado en propiedades
- Instalar SDKMan
sdk install java 11.0.12-open
instala OpenJDKsdk install sbt
una vez instalado SDKMan
- Descargar Visual Studio Code
- Instalar para VS Code Metals
- Por consola: Puedes instalar dependencias y lanzar los tests con
gradlew test
- Usando IDE: Simplemente abre el proyecto desde el raiz de la plantilla Kotlin
- Instalar Microsoft Visual Studio Community 2022
- Abre el proyecto y se descargaran automáticamente los paquetes Nuguet necesarios
- Instalar python 3.x
- Una vez descargado el código fuente dentro de la carpeta */python/ creamos un virtual enviroment:
python3 -m venv env
- Activamos en virtual environment:
- windows:
.\env\Scripts\activate.bat
- linux/mac:
source env/bin/activate
pytest
para ejecutar los tests.
- Instalar Go
go test -v
(en la carpeta con el archivo xxx_test.go)