Automatic Testing of Higher Order Functions

  • Pieter Koopman
  • Rinus Plasmeijer
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4279)

Abstract

This paper tackles a problem often overlooked in functional programming community: that of testing. Fully automatic test tools like Quickcheck and G ∀ ST can test first order functions successfully. Higher order functions, HOFs, are an essential and distinguishing part of functional languages. Testing HOFs automatically is still troublesome since it requires the generation of functions as test argument for the HOF to be tested. Also the functions that are the result of the higher order function needs to be identified. If a counter example is found, the generated and resulting functions should be printed, but that is impossible in most functional programming languages. Yet, bugs in HOFs do occur and are usually more subtle due to the high abstraction level.

In this paper we present an effective and efficient technique to test higher order functions by using intermediate data types. Such a data type mimics and controls the structure of the function to be generated. A simple additional function transforms this data structure to the function needed. We use a continuation based parser library as main example of the tests. Our automatic testing method for HOFs reveals errors in the library that was used for a couple of years without problems.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Alimarine, A., Plasmeijer, R.: A Generic Programming Extension for Clean. In: Arts, T., Mohnen, M. (eds.) IFL 2002. LNCS, vol. 2312, pp. 168–185. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  2. 2.
    Claessen, K., Hughes, J.: QuickCheck: A lightweight Tool for Random Testing of Haskell Programs. In: ICFP, pp. 268–279. ACM, New York (2000)CrossRefGoogle Scholar
  3. 3.
    Danvy, O., Nielsen, L.R.: Defunctionalization at Work. In: PPDP 2001 Proceedings, pp. 162–174 (2001)Google Scholar
  4. 4.
    Koopman, P., Plasmeijer, R.: Efficient Combinator Parsers. In: Hammond, K., Davie, T., Clack, C. (eds.) IFL 1998. LNCS, vol. 1595, pp. 120–136. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  5. 5.
    Koopman, P., Alimarine, A., Tretmans, J., Plasmeijer, R.: Gast: Generic Automated Software Testing. In: Peña, R., Arts, T. (eds.) IFL 2002. LNCS, vol. 2670, pp. 84–100. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  6. 6.
    Koopman, P., Plasmeijer, R.: Generic Generation of Elements of Types. In: Sixth Symposium on Trends in Functional Programming (TFP 2005) (2005)Google Scholar
  7. 7.
    Malcom, G.: Algebraic Data Types and Program Transformations, Thesis (1990)Google Scholar
  8. 8.
    Plasmeijer, R., van Eekelen, M.: Concurrent Clean Language Report (version 2.1.1) (2005), www.cs.ru.nl/~clean
  9. 9.
    Reynolds, J.C.: Definitional interpreters for higher-order programming languages. Higher-Order and Symbolic Computation 11(4), 363–397 (1998); Reprinted from the Proceedings of the 25th ACM National Conference (1972)MATHCrossRefGoogle Scholar
  10. 10.
    Wadler, P.: Monads for functional programming. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925. Springer, Heidelberg (1995)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Pieter Koopman
    • 1
  • Rinus Plasmeijer
    • 1
  1. 1.Nijmegen Institute for Computer and Information ScienceThe Netherlands

Personalised recommendations