summary refs log blame commit diff stats
path: root/test/tc_human_readable.py
blob: 493e6d3a59a62a656446c2e4b91aade2d63ea8dd (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
22
23
24
25
26
27
28
29
30
31
32
33
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os.path
import sys
rangerpath = os.path.join(os.path.dirname(__file__), '..')
if sys.path[1] != rangerpath:
	sys.path[1:1] = [rangerpath]

import unittest
from ranger.ext.human_readable import human_readable as hr

class HumanReadableTest(unittest.TestCase):
	def test_basic(self):
		self.assertEqual("0", hr(0))
		self.assertEqual("1 B", hr(1))
		self.assertEqual("1 K", hr(2 ** 10))
		self.assertEqual("1 M", hr(2 ** 20))
		self.assertEqual("1 G", hr(2 ** 30))
		self.assertEqual(">9000", hr(2 ** 100))

	def test_big(self):
		self.assertEqual("1023 G", hr(2 ** 30 * 1023))
		self.assertEqual("1024 G", hr(2 ** 40 - 1))
		self.assertEqual("1 T",    hr(2 ** 40))

	def test_small(self):
		self.assertEqual("1000 B", hr(1000))
		self.assertEqual("1.66 M", hr(1.66 * 2 ** 20))
		self.assertEqual("1.46 K", hr(1500))
		self.assertEqual("1.5 K",  hr(2 ** 10 + 2 ** 9))
		self.assertEqual("1.5 K",  hr(2 ** 10 + 2 ** 9 - 1))

	def test_no_exponent(self):
		for i in range(2 ** 10, 2 ** 20, 512):
			self.assertTrue('e' not in hr(i), "%d => %s" % (i, hr(i)))

if __name__ == '__main__':
	unittest.main()
">(A(I)(1) === 1, 'A failed'); console.assert(T(1)(I) === 1, 'T failed'); console.assert(W(I)(1) === 1, 'W failed'); // FIXME: Does this really work? console.assert(C(I)(1)(2) === 1, 'C failed'); console.assert(B(I)(I)(1) === 1, 'B failed'); console.assert(S(I)(I)(1) === 1, 'S failed'); console.assert(S_(I)(I)(1) === 1, 'S_ failed'); console.assert(S2(I)(I)(I)(1) === 1, 'S2 failed'); console.assert(P(I)(I)(1)(2) === 1, 'P failed'); console.assert(Y(I)(1) === 1, 'Y failed'); }()); // Count the number of live neighbors of a cell const countLiveNeighbors = B (A (B (A (B (A (K (A (I)))))))) (A (B (A (K (A (I)))))) const isAlive = cell => count => (cell && (count === 2 || count === 3)) || (!cell && count === 3) const rules = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I)))))) const nextState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I)))))) const nextBoardState = B (A (B (A (K (A (I)))))) (A (B (A (K (A (I)))))) // validate countLiveNeighbors rules (function() { // FIXME: I think I messed up these test values, maybe? // FIXME: I also don't think this'll work given that the combinators will only grok 1 arg that is another combinator...right? console.log('validating countLiveNeighbors'); console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 1, 1) === 4, 'countLiveNeighbors 1 failed'); console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 0, 0) === 2, 'countLiveNeighbors 2 failed'); console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 2, 2) === 4, 'countLiveNeighbors 3 failed'); console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 0, 2) === 2, 'countLiveNeighbors 4 failed'); console.assert(countLiveNeighbors([[true, false, true], [false, true, false], [true, false, true]], 2, 0) === 2, 'countLiveNeighbors 5 failed'); }()); // validate isAlive rules (function() { console.log('validating isAlive'); console.assert(isAlive(true)(2) === true, 'isAlive 1 failed'); console.assert(isAlive(true)(3) === true, 'isAlive 2 failed'); console.assert(isAlive(true)(4) === false, 'isAlive 3 failed'); console.assert(isAlive(false)(3) === true, 'isAlive 4 failed'); console.assert(isAlive(false)(2) === false, 'isAlive 5 failed'); }()); // validate rules (function() { console.log('validating rules'); console.assert(rules(true)(2) === true, 'rules 1 failed'); // console.assert(rules(true)(3) === true, 'rules 2 failed'); // console.assert(rules(true)(4) === false, 'rules 3 failed'); // console.assert(rules(false)(3) === true, 'rules 4 failed'); // console.assert(rules(false)(2) === false, 'rules 5 failed'); }()); // validate nextState rules (function() { // FIXME: something is up with Bluebird I think... console.log('validating nextState'); console.assert(nextState(true)(2) === true, 'nextState 1 failed'); console.assert(nextState(true)(3) === true, 'nextState 2 failed'); console.assert(nextState(true)(4) === false, 'nextState 3 failed'); console.assert(nextState(false)(3) === true, 'nextState 4 failed'); console.assert(nextState(false)(2) === false, 'nextState 5 failed'); }()); // validate nextBoardState rules (function() { console.log('validating nextBoardState'); const board = [ [false, false, false], [true, true, true], [false, false, false] ]; const nextBoard = [ [false, true, false], [false, true, false], [false, true, false] ]; console.assert(JSON.stringify(nextBoardState(board)) === JSON.stringify(nextBoard), 'nextBoardState 1 failed'); }());