So I like test-driven development and frequently I have wanted a programming language to assist with the creation of test routines. I have wanted to define the domain of a function and then have some test 'buddy' generate some random test input based on the domain, some test data deliberately inside the domain and some deliberately outside to test the error case, also some deliberately on the boundary which is where more errors can occur.
It seems possible with a custom C# attribute adorned on a method parameters. However, I would like an extra level of cleverness I would like inferred domains, inferred from the domains of feeder functions. I should introduce some example code at this point, the following is VBA and illustrates a case where (given enough language support) the domain of
i(x) could be inferred by looking at the domains of
Option Explicit '* I'd like to define the domain of g(x) to be 2 <= x <= 5 , whilst g(x) maps x->x+1 Function g(x) If Not (2 <= x And x <= 5) Then g = CVErr(2011): Exit Function '* VBA domain screened with If g = x + 1 End Function '* I'd like to define the domain of h(x) to be -4 <= x <= 4, whilst h(x) maps x->x^2 Function h(x) If Not (-4 <= x And x <= 4) Then h = CVErr(2011): Exit Function '* VBA domain screened with If h = x ^ 2 End Function Function i(x) '* it would be nice if a computer language could understand that the domain of i(x) can '* be inferred from the domains '* of g(x) and h(x) and is thus 2 <= x <= 3 '* obviating the need for me to write the line explicitly i = h(g(x)) End Function
Sorry if this is a contrived example but real world instances do arise in my experience.
I guess in formal terms the language would need 'declarative definition of function domains'.
So could, in theory, a programming language support this?
Could this be related to Constraint programming - Wikipedia?