[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: unit testing in a functional language
- From: mitch abaza <mitch.abaza@...>
- Date: Thu, 20 Sep 2012 21:09:15 -0500
I come from a heavy TDD/OOP background and I'm finding it challenging to apply the same testing discipline to Lua. Here's the problem domain I'm trying to tackle:
I have a bunch of "rules" (ie: functions) and I want to apply some of
those rules to certain customer data. I have a configuration system that says,
"When applying rules to data from customer X, use this set of rules."
I've come up with three modules:
filterRulesLibrary == contains a list of available rules (functions)
configSystem == determines which rules should be applied for a given customer
filterRuleProvider = module that uses the two above modules to return a table of functions (rules) to the client application
Sample Code
==========================================================
--5.2 module style
local filterRuleProvider ={}
filterRuleProvider = require("filterRules")
configSystem =require("configSystem ")
filterRuleProvider.assembleRules = function(facilityId)
local filters = {}
if ( configSystem .shouldFilterEmptyMessages(facilityId)) then
table.insert(filters,filterRuleProvider.filterEmptyMessages)
end
return filters
end
return filterRuleProvider
==========================================================
I'm told you can't do reference equality on functions. If true, how would I test that the returned table contains a "reference" to the filterRuleProvider.filterEmptyMessages function?