@@ -0,0 +1,2033 @@
+#!/usr/bin/env python%0A# ----------------------------------------------------------------------%0A# Numenta Platform for Intelligent Computing (NuPIC)%0A# Copyright (C) 2013, Numenta, Inc.  Unless you have purchased from%0A# Numenta, Inc. a separate commercial license for this software code, the%0A# following terms and conditions apply:%0A#%0A# This program is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU General Public License version 3 as%0A# published by the Free Software Foundation.%0A#%0A# This program is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.%0A# See the GNU General Public License for more details.%0A#%0A# You should have received a copy of the GNU General Public License%0A# along with this program.  If not, see http://www.gnu.org/licenses.%0A#%0A# http://numenta.org/licenses/%0A# ----------------------------------------------------------------------%0A%0A%0Aimport unittest2 as unittest%0A%0A%0Afrom nupic.encoders.scalar import ScalarEncoder%0Afrom nupic.encoders.vector import VectorEncoder%0Afrom nupic.encoders.utility import UtilityEncoder%0A%0Aclass UtilityEncoderTest(unittest.TestCase):%0A  %22%22%22testing Utility encoder%22%22%22%0A%0A  def setUp(self):%0A    self.data = %5B1,2,3%5D%0A%0A    # encoder for score: 0..100, fine-grained to 0.5%0A    self.scoreEnc = ScalarEncoder(3, 0, 100, resolution=0.5, name='score')%0A%0A    # encoder for the input (data) part%0A    elem = ScalarEncoder(1,0,3,resolution=1)%0A    self.dataEnc = VectorEncoder(len(self.data), elem, typeCastFn=int, name='data')%0A%0A    # utility encoder%0A    def sumAll(list):%0A      return sum(list)%0A%0A    self.fn = sumAll%0A%0A    self.utilityEnc = None%0A%0A  def testInitialization(self):%0A    %22%22%22creating a utility encoder%22%22%22%0A    util = UtilityEncoder(self.dataEnc, self.scoreEnc, feval=self.fn, name='starter')%0A    assert True==isinstance(util, UtilityEncoder)%0A%0A##########################################################%0Aif __name__ == '__main__':%0A  unittest.main()%0A

add unittest