# Copyright (c) 2009 Tim Freeman # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # # (This is the standard MIT License, copied from # http://www.opensource.org/licenses/mit-license.php on 24 Apr 2007.) from speed_prior import Speed_prior import bits assert Speed_prior(1,2,3) == Speed_prior(1,2,3) assert Speed_prior(1,2,3) != Speed_prior(1,2,4) assert Speed_prior.generator(3) == [ Speed_prior(logtime=a, program_length=b, program=c) for (a,b,c) in [(0, 3, 0), (0, 3, 1), (0, 3, 2), (0, 3, 3), (0, 3, 4), (0, 3, 5), (0, 3, 6), (0, 3, 7), (1, 2, 0), (1, 2, 1), (1, 2, 2), (1, 2, 3), (2, 1, 0), (2, 1, 1), (3, 0, 0)]] def make(a, b, c): return Speed_prior(logtime=a, program_length=b, program=c) assert bits.many_bits(2, [bits.exact_bits, Speed_prior.generator]) == \ [[0, make(0, 2, 0)], [0, make(0, 2, 1)], [0, make(0, 2, 2)], [0, make(0, 2, 3)], [0, make(1, 1, 0)], [0, make(1, 1, 1)], [0, make(2, 0, 0)], [0, make(0, 1, 0)], [0, make(0, 1, 1)], [0, make(1, 0, 0)], [1, make(0, 1, 0)], [1, make(0, 1, 1)], [1, make(1, 0, 0)], [0, make(0, 0, 0)], [1, make(0, 0, 0)], [2, make(0, 0, 0)], [3, make(0, 0, 0)]] assert make(0, 0, 0).measure() == 1 assert make(1, 0, 0).measure() == 0.5 # Penalize once for the run time and twice for the length, for a total of 3. # 2 ** -3 = 0.125. assert make(1, 1, 1).measure() == 0.125 assert not(make(0,3,2) != make(0,3,2)) assert make(0,3,2) != False assert make(0,3,2) == make(0,3,2) assert make(5,6,7).program_length() == 6 assert make(5,3,7).is_prefix(make(5,4,7)) assert make(5,3,7).is_prefix(make(5,4,15)) assert not make(5,3,7).is_prefix(make(5,4,5)) assert "logtime" in "%r" % (Speed_prior(1,2,3),)