Testing Polymorphic Properties

  • Jean-Philippe Bernardy
  • Patrik Jansson
  • Koen Claessen
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6012)

Abstract

This paper is concerned with testing properties of polymorphic functions. The problem is that testing can only be performed on specific monomorphic instances, whereas parametrically polymorphic functions are expected to work for any type. We present a schema for constructing a monomorphic instance for a polymorphic property, such that correctness of that single instance implies correctness for all other instances. We also give a formal definition of the class of polymorphic properties the schema can be used for. Compared to the standard method of testing such properties, our schema leads to a significant reduction of necessary test cases.

Keywords

polymorphism parametricity initiality testing 

References

  1. 1.
    Abbott, M., Altenkirch, T., Ghani, N.: Categories of containers. In: Gordon, A.D. (ed.) FOSSACS 2003. LNCS, vol. 2620, pp. 23–38. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  2. 2.
    Arts, T., Hughes, J., Johansson, J., Wiger, U.: Testing telecoms software with quviq QuickCheck. In: Proc. of the 2006 ACM SIGPLAN workshop on Erlang, pp. 2–10. ACM, New York (2006)CrossRefGoogle Scholar
  3. 3.
    Bagge, A.H., David, V., Haveraaen, M.: Axiom-based testing for C++. In: Companion to the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applications, pp. 721–722. ACM, New York (2008)CrossRefGoogle Scholar
  4. 4.
    Bird, R., de Moor, O.: Algebra of programming. Prentice-Hall, Englewood Cliffs (1997)MATHGoogle Scholar
  5. 5.
    Böhm, C., Berarducci, A.: Automatic synthesis of typed lambda-programs on term algebras. Theoretical Computer Science 39(2-3), 135–154 (1985)MATHCrossRefMathSciNetGoogle Scholar
  6. 6.
    Christiansen, J., Fischer, S.: EasyCheck — test data for free. In: Garrigue, J., Hermenegildo, M.V. (eds.) FLOPS 2008. LNCS, vol. 4989, pp. 322–336. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  7. 7.
    Claessen, K., Hughes, J.: QuickCheck: a lightweight tool for random testing of Haskell programs. In: Proc. of the fifth ACM SIGPLAN international conference on Functional programming, pp. 268–279. ACM, New York (2000)CrossRefGoogle Scholar
  8. 8.
    Danielsson, N.A., Gibbons, J., Hughes, J., Jansson, P.: Fast and loose reasoning is morally correct. In: POPL 2006, pp. 206–217. ACM Press, New York (2006)CrossRefGoogle Scholar
  9. 9.
    Danvy, O., Nielsen, L.R.: Defunctionalization at work. In: Proc. of the 3rd ACM SIGPLAN international conference on Principles and practice of declarative programming, pp. 162–174. ACM, New York (2001)CrossRefGoogle Scholar
  10. 10.
    Davey, B.A., Priestley, H.A.: Introduction to lattices and order. Cambridge University Press, Cambridge (2002)MATHGoogle Scholar
  11. 11.
    Day, N.A., Launchbury, J., Lewis, J.: Logical abstractions in Haskell. In: Proc. of the 1999 Haskell Workshop (1999)Google Scholar
  12. 12.
    Fegaras, L., Sheard, T.: Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space). In: Proc. of the 23rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 284–294. ACM, New York (1996)CrossRefGoogle Scholar
  13. 13.
    Fokkinga, M.M.: Datatype laws without signatures. Mathematical Structures in Computer Science 6(01), 1–32 (1996)MATHCrossRefMathSciNetGoogle Scholar
  14. 14.
    Gill, A., Launchbury, J., Peyton Jones, S.L.: A short cut to deforestation. In: Proc. of the conference on Functional programming languages and computer architecture, pp. 223–232. ACM, New York (1993)CrossRefGoogle Scholar
  15. 15.
    Hinze, R.: Church numerals, twice! J. of Funct. Program 15(01), 1–13 (2005)MATHCrossRefGoogle Scholar
  16. 16.
    Hoffman, D., Nair, J., Strooper, P.: Testing generic Ada packages with APE. Ada Lett. XVIII(6), 255–262 (1998)Google Scholar
  17. 17.
    Jansson, P., Jeuring, J., Cabenda, L., Engels, G., Kleerekoper, J., Mak, S., Overeem, M., Visser, K.: Testing properties of generic functions. In: Horváth, Z., Zsók, V., Butterfield, A. (eds.) IFL 2006. LNCS, vol. 4449, pp. 217–234. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  18. 18.
    Johann, P., Voigtländer, J.: Free theorems in the presence of seq. In: Proc. of the 31st ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 99–110. ACM, New York (2004)CrossRefGoogle Scholar
  19. 19.
    Knuth, D.E.: The Art of Computer Programming, 2nd edn. Sorting and Searching, vol. 3. Addison-Wesley Professional, Reading (1998)Google Scholar
  20. 20.
    Nilsson, R.: ScalaCheck (2009), http://code.google.com/p/scalacheck/
  21. 21.
    Pottier, F., Gauthier, N.: Polymorphic typed defunctionalization and concretization. Higher-Order Symbol. Comput. 19(1), 125–162 (2006)MATHCrossRefGoogle Scholar
  22. 22.
    Reynolds, J.C.: Definitional interpreters for Higher-Order programming languages. Higher Order Symbol. Comput. 11(4), 363–397 (1998)MATHCrossRefGoogle Scholar
  23. 23.
    Runciman, C., Naylor, M., Lindblad, F.: Smallcheck and lazy smallcheck: automatic exhaustive testing for small values. In: Proc. of the first ACM SIGPLAN symposium on Haskell, pp. 37–48. ACM, New York (2008)CrossRefGoogle Scholar
  24. 24.
    Saff, D.: Theory-infected: or how i learned to stop worrying and love universal quantification. In: Companion to the 22nd ACM SIGPLAN conference on Object-oriented programming systems and applications companion, pp. 846–847. ACM, New York (2007)Google Scholar
  25. 25.
    Sheeran, M.: Hardware design and functional programming: a perfect match. Talk at Hardware Design and Functional Languages (2007)Google Scholar
  26. 26.
    Svenningsson, J.: Shortcut fusion for accumulating parameters & zip-like functions. In: Proc. of the seventh ACM SIGPLAN international conference on Functional programming, vol. 37, pp. 124–132. ACM, New York (2002)CrossRefGoogle Scholar
  27. 27.
    Tillmann, N., Schulte, W.: Parameterized unit tests. SIGSOFT Softw. Eng. Notes 30(5), 253–262 (2005)CrossRefGoogle Scholar
  28. 28.
    Voigtländer, J.: Much ado about two (pearl): a pearl on parallel prefix computation. SIGPLAN Not. 43(1), 29–35 (2008)CrossRefGoogle Scholar
  29. 29.
    Wadler, P.: Theorems for free! In: Proc. of the fourth international conference on Functional programming languages and computer architecture, pp. 347–359. ACM, New York (1989)CrossRefGoogle Scholar
  30. 30.
    Washburn, G., Weirich, S.: Boxes go bananas: encoding higher-order abstract syntax with parametric polymorphism. In: Proc. of the eighth ACM SIGPLAN international conference on Functional programming, pp. 249–262. ACM, New York (2003)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2010

Authors and Affiliations

  • Jean-Philippe Bernardy
    • 1
  • Patrik Jansson
    • 1
  • Koen Claessen
    • 1
  1. 1.Chalmers University of Technology 

Personalised recommendations