#!/usr/bin/env python # -------------------------------- # Copyright (c) 2013 "Capensis" [http://www.capensis.com] # # This file is part of Canopsis. # # Canopsis is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Canopsis is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with Canopsis. If not, see <http://www.gnu.org/licenses/>. # --------------------------------- """ Testing program execution Go to http://ks.utopland.net/runpy/run.php?filename=snippets """ class MeanCalculator(object): """ 1. This class registers each instance statically, to allow access from the static property INSTANCES 2. compute_means which gives the mean of a set of numbers 3. The property "value """ INSTANCES = [] def init(self): self.value = None register_instance(self) def abstract_method(this): def compute_means(number_list): #TODO Compute a mean from a list of number return self.value def register_instance(self): """ Register self instance in MeanCalculator class, to allow static access to all instances. """ self.INSTANCES = self def test1(): # check if an instance is registered in MeanCalculator return False def test2(): result = list() mean_list = [(1,2,3), (4,5,6), (7,8,9)] result = map(lambda x: MeanCalculator().compute_means(x), mean_list) return result == [2,5,8] def unit_tests(): assert(test1()) assert(test2()) if __name__ == "__main__": unit_tests() print 'DONE'
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question