Automatic test-case generation for Haskell based on dependent types

Software testing is the simplest and most widespread approach to finding bugs in computer programs, where bugs are understood as a discrepancy between the expected output of the program and its actual output. Testing has the disadvantage of requiring a previous generation of a suite of test cases—in...

Descripción completa

Detalles Bibliográficos
Autor: Castellanos García, Pablo
Tipo de recurso: tesis de maestría
Fecha de publicación:2024
País:España
Institución:Universidad Complutense de Madrid (UCM)
Repositorio:Docta Complutense
Idioma:inglés
OAI Identifier:oai:docta.ucm.es:20.500.14352/107971
Acceso en línea:https://hdl.handle.net/20.500.14352/107971
Access Level:acceso abierto
Palabra clave:004(043.3)
Haskell
Property-Based Testing
GADTs
Dependent types
Prolog
Tipos dependientes
Informática (Informática)
33 Ciencias Tecnológicas
Descripción
Sumario:Software testing is the simplest and most widespread approach to finding bugs in computer programs, where bugs are understood as a discrepancy between the expected output of the program and its actual output. Testing has the disadvantage of requiring a previous generation of a suite of test cases—inputs to the program that are representative of the whole input space—together with the expected outputs. Property-based testing addresses this issue by requiring only a formal specification of the intended behavior of the code and generating test cases automatically: then, the functional correctness of the program can be tested empirically by checking if the output of the program when given the generated test cases as input satisfies the specification. A naïve implementation of property-based testing behaves poorly when the tested program has non-trivial preconditions: these are usually written in the specification as a conditional statement of the form “if the input meets some condition, then the output should satisfy some other condition”, but values generated at random frequently do not satisfy the precondition, meaning that the specification holds vacuously—a false premise makes any implication true, regardless of the conclusion. Our work aims to solve the above problem by using a dependent type system to encode the desired preconditions at the type level. We start by developing a mechanism to automatically construct test case generators from data type declarations. Then, we show how dependent types can be simulated in Haskell using advanced features such as GADTs and data type promotion, and finally we extend our mechanism to translate (simulated) dependent type declarations into test case generators that only produce values satisfying the specified precondition.