How to use equal method in Sure

Best Python code snippet using sure_python

test_fstring.py

Source:test_fstring.py Github

copy

Full Screen

...739 self.assertEqual(f'expr={ {x: y for x, y in [(1, 2), ]}}',740 'expr={1: 2}')741 self.assertEqual(f'expr={ {x: y for x, y in [(1, 2), ]} }',742 'expr={1: 2}')743 def test_not_equal(self):744 # There's a special test for this because there's a special745 # case in the f-string parser to look for != as not ending an746 # expression. Normally it would, while looking for !s or !r.747 self.assertEqual(f'{3!=4}', 'True')748 self.assertEqual(f'{3!=4:}', 'True')749 self.assertEqual(f'{3!=4!s}', 'True')750 self.assertEqual(f'{3!=4!s:.3}', 'Tru')751 def test_conversions(self):752 self.assertEqual(f'{3.14:10.10}', ' 3.14')753 self.assertEqual(f'{3.14!s:10.10}', '3.14 ')754 self.assertEqual(f'{3.14!r:10.10}', '3.14 ')755 self.assertEqual(f'{3.14!a:10.10}', '3.14 ')756 self.assertEqual(f'{"a"}', 'a')757 self.assertEqual(f'{"a"!r}', "'a'")...

Full Screen

Full Screen

test_Cluster.py

Source:test_Cluster.py Github

copy

Full Screen

1import unittest2import numpy3class TestCluster(unittest.TestCase):4 module = 'Bio.Cluster'5 def test_median_mean(self):6 if TestCluster.module=='Bio.Cluster':7 from Bio.Cluster import mean, median8 elif TestCluster.module=='Pycluster':9 from Pycluster import mean, median10 data = numpy.array([ 34.3, 3, 2 ])11 self.assertAlmostEqual(mean(data), 13.1, places=3)12 self.assertAlmostEqual(median(data), 3.0, places=3)13 data = [ 5, 10, 15, 20]14 self.assertAlmostEqual(mean(data), 12.5, places=3)15 self.assertAlmostEqual(median(data), 12.5, places=3)16 data = [ 1, 2, 3, 5, 7, 11, 13, 17]17 self.assertAlmostEqual(mean(data), 7.375, places=3)18 self.assertAlmostEqual(median(data), 6.0, places=3)19 data = [ 100, 19, 3, 1.5, 1.4, 1, 1, 1]20 self.assertAlmostEqual(mean(data), 15.988, places=3)21 self.assertAlmostEqual(median(data), 1.45, places=3)22 23 def test_matrix_parse(self):24 if TestCluster.module=='Bio.Cluster':25 from Bio.Cluster import treecluster26 elif TestCluster.module=='Pycluster':27 from Pycluster import treecluster28 # Normal matrix, no errors29 data1 = numpy.array([[ 1.1, 1.2 ],30 [ 1.4, 1.3 ],31 [ 1.1, 1.5 ],32 [ 2.0, 1.5 ],33 [ 1.7, 1.9 ],34 [ 1.7, 1.9 ],35 [ 5.7, 5.9 ],36 [ 5.7, 5.9 ],37 [ 3.1, 3.3 ],38 [ 5.4, 5.3 ],39 [ 5.1, 5.5 ],40 [ 5.0, 5.5 ],41 [ 5.1, 5.2 ]])42 43 # Another normal matrix, no errors; written as a list44 data2 = [[ 1.1, 2.2, 3.3, 4.4, 5.5 ], 45 [ 3.1, 3.2, 1.3, 2.4, 1.5 ], 46 [ 4.1, 2.2, 0.3, 5.4, 0.5 ], 47 [ 12.1, 2.0, 0.0, 5.0, 0.0 ]]48 49 # Ragged matrix50 data3 = [[ 91.1, 92.2, 93.3, 94.4, 95.5], 51 [ 93.1, 93.2, 91.3, 92.4 ], 52 [ 94.1, 92.2, 90.3 ], 53 [ 12.1, 92.0, 90.0, 95.0, 90.0 ]]54 55 # Matrix with bad cells56 data4 = [ [ 7.1, 7.2, 7.3, 7.4, 7.5, ],57 [ 7.1, 7.2, 7.3, 7.4, 'snoopy' ], 58 [ 7.1, 7.2, 7.3, None, None]] 59 # Matrix with a bad row60 data5 = [ [ 23.1, 23.2, 23.3, 23.4, 23.5], 61 None,62 [ 23.1, 23.0, 23.0, 23.0, 23.0]]63 # Various references that don't point to matrices at all64 data6 = "snoopy"65 data7 = {'a': [[2.3,1.2],[3.3,5.6]]}66 data8 = []67 data9 = [None]68 69 try:70 treecluster(data1)71 except:72 self.fail("treecluster failed to accept matrix data1")73 try:74 treecluster(data2)75 except:76 self.fail("treecluster failed to accept matrix data2")77 self.assertRaises(TypeError, lambda : treecluster(data3))78 self.assertRaises(TypeError, lambda : treecluster(data4))79 self.assertRaises(TypeError, lambda : treecluster(data5))80 self.assertRaises(TypeError, lambda : treecluster(data6))81 self.assertRaises(TypeError, lambda : treecluster(data7))82 self.assertRaises(TypeError, lambda : treecluster(data8))83 self.assertRaises(TypeError, lambda : treecluster(data9))84 def test_kcluster(self):85 if TestCluster.module=='Bio.Cluster':86 from Bio.Cluster import kcluster87 elif TestCluster.module=='Pycluster':88 from Pycluster import kcluster89 nclusters = 390 # First data set91 weight = numpy.array([1,1,1,1,1])92 data = numpy.array([[ 1.1, 2.2, 3.3, 4.4, 5.5],93 [ 3.1, 3.2, 1.3, 2.4, 1.5], 94 [ 4.1, 2.2, 0.3, 5.4, 0.5], 95 [12.1, 2.0, 0.0, 5.0, 0.0]]) 96 mask = numpy.array([[ 1, 1, 1, 1, 1], 97 [ 1, 1, 1, 1, 1], 98 [ 1, 1, 1, 1, 1], 99 [ 1, 1, 1, 1, 1]], int) 100 101 clusterid, error, nfound = kcluster(data, nclusters=nclusters,102 mask=mask, weight=weight,103 transpose=0, npass=100,104 method='a', dist='e')105 self.assertEqual(len(clusterid), len(data))106 correct = [0,1,1,2]107 mapping = [clusterid[correct.index(i)] for i in range(nclusters)]108 for i in range(len(clusterid)):109 self.assertEqual(clusterid[i], mapping[correct[i]])110 111 # Second data set112 weight = numpy.array([1,1])113 data = numpy.array([[ 1.1, 1.2 ],114 [ 1.4, 1.3 ],115 [ 1.1, 1.5 ],116 [ 2.0, 1.5 ],117 [ 1.7, 1.9 ],118 [ 1.7, 1.9 ],119 [ 5.7, 5.9 ],120 [ 5.7, 5.9 ],121 [ 3.1, 3.3 ],122 [ 5.4, 5.3 ],123 [ 5.1, 5.5 ],124 [ 5.0, 5.5 ],125 [ 5.1, 5.2 ]])126 mask = numpy.array([[ 1, 1 ],127 [ 1, 1 ],128 [ 1, 1 ],129 [ 1, 1 ],130 [ 1, 1 ],131 [ 1, 1 ],132 [ 1, 1 ],133 [ 1, 1 ],134 [ 1, 1 ],135 [ 1, 1 ],136 [ 1, 1 ],137 [ 1, 1 ],138 [ 1, 1 ]], int)139 clusterid, error, nfound = kcluster(data, nclusters=3, mask=mask,140 weight=weight, transpose=0,141 npass=100, method='a', dist='e')142 self.assertEqual(len(clusterid), len(data))143 correct = [0, 0, 0, 0, 0, 0, 1, 1, 2, 1, 1, 1, 1]144 mapping = [clusterid[correct.index(i)] for i in range(nclusters)]145 for i in range(len(clusterid)):146 self.assertEqual(clusterid[i], mapping[correct[i]])147 def test_clusterdistance(self):148 if TestCluster.module=='Bio.Cluster':149 from Bio.Cluster import clusterdistance150 elif TestCluster.module=='Pycluster':151 from Pycluster import clusterdistance152 # First data set153 weight = numpy.array([ 1,1,1,1,1 ])154 data = numpy.array([[ 1.1, 2.2, 3.3, 4.4, 5.5, ], 155 [ 3.1, 3.2, 1.3, 2.4, 1.5, ], 156 [ 4.1, 2.2, 0.3, 5.4, 0.5, ], 157 [ 12.1, 2.0, 0.0, 5.0, 0.0, ]])158 mask = numpy.array([[ 1, 1, 1, 1, 1], 159 [ 1, 1, 1, 1, 1], 160 [ 1, 1, 1, 1, 1], 161 [ 1, 1, 1, 1, 1]], int)162 # Cluster assignments163 c1 = [0]164 c2 = [1,2]165 c3 = [3]166 distance = clusterdistance(data, mask=mask, weight=weight,167 index1=c1, index2=c2, dist='e',168 method='a', transpose=0);169 self.assertAlmostEqual(distance, 6.650, places=3)170 distance = clusterdistance(data, mask=mask, weight=weight,171 index1=c1, index2=c3, dist='e',172 method='a', transpose=0);173 self.assertAlmostEqual(distance, 32.508, places=3)174 distance = clusterdistance(data, mask=mask, weight=weight,175 index1=c2, index2=c3, dist='e',176 method='a', transpose=0);177 self.assertAlmostEqual(distance, 15.118, places=3)178 # Second data set179 weight = numpy.array([ 1,1 ])180 data = numpy.array([[ 1.1, 1.2 ],181 [ 1.4, 1.3 ],182 [ 1.1, 1.5 ],183 [ 2.0, 1.5 ],184 [ 1.7, 1.9 ],185 [ 1.7, 1.9 ],186 [ 5.7, 5.9 ],187 [ 5.7, 5.9 ],188 [ 3.1, 3.3 ],189 [ 5.4, 5.3 ],190 [ 5.1, 5.5 ],191 [ 5.0, 5.5 ],192 [ 5.1, 5.2 ]])193 mask = numpy.array([[ 1, 1 ],194 [ 1, 1 ],195 [ 1, 1 ],196 [ 1, 1 ],197 [ 1, 1 ],198 [ 1, 1 ],199 [ 1, 1 ],200 [ 1, 1 ],201 [ 1, 1 ],202 [ 1, 1 ],203 [ 1, 1 ],204 [ 1, 1 ],205 [ 1, 1 ]], int)206 # Cluster assignments207 c1 = [ 0, 1, 2, 3 ]208 c2 = [ 4, 5, 6, 7 ]209 c3 = [ 8 ]210 distance = clusterdistance(data, mask=mask, weight=weight,211 index1=c1, index2=c2, dist='e',212 method='a', transpose=0);213 self.assertAlmostEqual(distance, 5.833, places=3)214 distance = clusterdistance(data, mask=mask, weight=weight,215 index1=c1, index2=c3, dist='e',216 method='a', transpose=0);217 self.assertAlmostEqual(distance, 3.298, places=3)218 distance = clusterdistance(data, mask=mask, weight=weight,219 index1=c2, index2=c3, dist='e',220 method='a', transpose=0);221 self.assertAlmostEqual(distance, 0.360, places=3)222 def test_treecluster(self):223 if TestCluster.module=='Bio.Cluster':224 from Bio.Cluster import treecluster225 elif TestCluster.module=='Pycluster':226 from Pycluster import treecluster227 # First data set228 weight1 = [ 1,1,1,1,1 ]229 data1 = numpy.array([[ 1.1, 2.2, 3.3, 4.4, 5.5], 230 [ 3.1, 3.2, 1.3, 2.4, 1.5], 231 [ 4.1, 2.2, 0.3, 5.4, 0.5], 232 [ 12.1, 2.0, 0.0, 5.0, 0.0]])233 mask1 = numpy.array([[ 1, 1, 1, 1, 1], 234 [ 1, 1, 1, 1, 1], 235 [ 1, 1, 1, 1, 1], 236 [ 1, 1, 1, 1, 1]], int)237 238 # test first data set239 # Pairwise average-linkage clustering"240 tree = treecluster(data=data1, mask=mask1, weight=weight1,241 transpose=0, method='a', dist='e')242 self.assertEqual(len(tree), len(data1)-1)243 self.assertEqual(tree[0].left, 2)244 self.assertEqual(tree[0].right, 1)245 self.assertAlmostEqual(tree[0].distance, 2.600, places=3)246 self.assertEqual(tree[1].left, -1)247 self.assertEqual(tree[1].right, 0)248 self.assertAlmostEqual(tree[1].distance, 7.300, places=3)249 self.assertEqual(tree[2].left, 3)250 self.assertEqual(tree[2].right, -2)251 self.assertAlmostEqual(tree[2].distance, 21.348, places=3)252 # Pairwise single-linkage clustering253 tree = treecluster(data=data1, mask=mask1, weight=weight1,254 transpose=0, method='s', dist='e')255 self.assertEqual(len(tree), len(data1)-1)256 self.assertEqual(tree[0].left, 1)257 self.assertEqual(tree[0].right, 2)258 self.assertAlmostEqual(tree[0].distance, 2.600, places=3)259 self.assertEqual(tree[1].left, 0)260 self.assertEqual(tree[1].right, -1)261 self.assertAlmostEqual(tree[1].distance, 5.800, places=3)262 self.assertEqual(tree[2].left, -2)263 self.assertEqual(tree[2].right, 3)264 self.assertAlmostEqual(tree[2].distance, 12.908, places=3)265 # Pairwise centroid-linkage clustering266 tree = treecluster(data=data1, mask=mask1, weight=weight1,267 transpose=0, method='c', dist='e')268 self.assertEqual(len(tree), len(data1)-1)269 self.assertEqual(tree[0].left, 1)270 self.assertEqual(tree[0].right, 2)271 self.assertAlmostEqual(tree[0].distance, 2.600, places=3)272 self.assertEqual(tree[1].left, 0)273 self.assertEqual(tree[1].right, -1)274 self.assertAlmostEqual(tree[1].distance, 6.650, places=3)275 self.assertEqual(tree[2].left, -2)276 self.assertEqual(tree[2].right, 3)277 self.assertAlmostEqual(tree[2].distance, 19.437, places=3)278 # Pairwise maximum-linkage clustering279 tree = treecluster(data=data1, mask=mask1, weight=weight1,280 transpose=0, method='m', dist='e')281 self.assertEqual(len(tree), len(data1)-1)282 self.assertEqual(tree[0].left, 2)283 self.assertEqual(tree[0].right, 1)284 self.assertAlmostEqual(tree[0].distance, 2.600, places=3)285 self.assertEqual(tree[1].left, -1)286 self.assertEqual(tree[1].right, 0)287 self.assertAlmostEqual(tree[1].distance, 8.800, places=3)288 self.assertEqual(tree[2].left, 3)289 self.assertEqual(tree[2].right, -2)290 self.assertAlmostEqual(tree[2].distance, 32.508, places=3)291 292 # Second data set293 weight2 = [ 1,1 ]294 data2 = numpy.array([[ 0.8223, 0.9295 ],295 [ 1.4365, 1.3223 ],296 [ 1.1623, 1.5364 ],297 [ 2.1826, 1.1934 ],298 [ 1.7763, 1.9352 ],299 [ 1.7215, 1.9912 ],300 [ 2.1812, 5.9935 ],301 [ 5.3290, 5.9452 ],302 [ 3.1491, 3.3454 ],303 [ 5.1923, 5.3156 ],304 [ 4.7735, 5.4012 ],305 [ 5.1297, 5.5645 ],306 [ 5.3934, 5.1823 ]])307 mask2 = numpy.array([[ 1, 1 ],308 [ 1, 1 ],309 [ 1, 1 ],310 [ 1, 1 ],311 [ 1, 1 ],312 [ 1, 1 ],313 [ 1, 1 ],314 [ 1, 1 ],315 [ 1, 1 ],316 [ 1, 1 ],317 [ 1, 1 ],318 [ 1, 1 ],319 [ 1, 1 ]], int)320 321 # Test second data set322 # Pairwise average-linkage clustering323 tree = treecluster(data=data2, mask=mask2, weight=weight2,324 transpose=0, method='a', dist='e')325 self.assertEqual(len(tree), len(data2)-1)326 self.assertEqual(tree[0].left, 5)327 self.assertEqual(tree[0].right, 4)328 self.assertAlmostEqual(tree[0].distance, 0.003, places=3)329 self.assertEqual(tree[1].left, 9)330 self.assertEqual(tree[1].right, 12)331 self.assertAlmostEqual(tree[1].distance, 0.029, places=3)332 self.assertEqual(tree[2].left, 2)333 self.assertEqual(tree[2].right, 1)334 self.assertAlmostEqual(tree[2].distance, 0.061, places=3)335 self.assertEqual(tree[3].left, 11)336 self.assertEqual(tree[3].right, -2)337 self.assertAlmostEqual(tree[3].distance, 0.070, places=3)338 self.assertEqual(tree[4].left, -4)339 self.assertEqual(tree[4].right, 10)340 self.assertAlmostEqual(tree[4].distance, 0.128, places=3)341 self.assertEqual(tree[5].left, 7)342 self.assertEqual(tree[5].right, -5)343 self.assertAlmostEqual(tree[5].distance, 0.224, places=3)344 self.assertEqual(tree[6].left, -3)345 self.assertEqual(tree[6].right, 0)346 self.assertAlmostEqual(tree[6].distance, 0.254, places=3)347 self.assertEqual(tree[7].left, -1)348 self.assertEqual(tree[7].right, 3)349 self.assertAlmostEqual(tree[7].distance, 0.391, places=3)350 self.assertEqual(tree[8].left, -8)351 self.assertEqual(tree[8].right, -7)352 self.assertAlmostEqual(tree[8].distance, 0.532, places=3)353 self.assertEqual(tree[9].left, 8)354 self.assertEqual(tree[9].right, -9)355 self.assertAlmostEqual(tree[9].distance, 3.234, places=3)356 self.assertEqual(tree[10].left, -6)357 self.assertEqual(tree[10].right, 6)358 self.assertAlmostEqual(tree[10].distance, 4.636, places=3)359 self.assertEqual(tree[11].left, -11)360 self.assertEqual(tree[11].right, -10)361 self.assertAlmostEqual(tree[11].distance, 12.741, places=3)362 363 # Pairwise single-linkage clustering364 tree = treecluster(data=data2, mask=mask2, weight=weight2,365 transpose=0, method='s', dist='e')366 self.assertEqual(len(tree), len(data2)-1)367 self.assertEqual(tree[0].left, 4)368 self.assertEqual(tree[0].right, 5)369 self.assertAlmostEqual(tree[0].distance, 0.003, places=3)370 self.assertEqual(tree[1].left, 9)371 self.assertEqual(tree[1].right, 12)372 self.assertAlmostEqual(tree[1].distance, 0.029, places=3)373 self.assertEqual(tree[2].left, 11)374 self.assertEqual(tree[2].right, -2)375 self.assertAlmostEqual(tree[2].distance, 0.033, places=3)376 self.assertEqual(tree[3].left, 1)377 self.assertEqual(tree[3].right, 2)378 self.assertAlmostEqual(tree[3].distance, 0.061, places=3)379 self.assertEqual(tree[4].left, 10)380 self.assertEqual(tree[4].right, -3)381 self.assertAlmostEqual(tree[4].distance, 0.077, places=3)382 self.assertEqual(tree[5].left, 7)383 self.assertEqual(tree[5].right, -5)384 self.assertAlmostEqual(tree[5].distance, 0.092, places=3)385 self.assertEqual(tree[6].left, 0)386 self.assertEqual(tree[6].right, -4)387 self.assertAlmostEqual(tree[6].distance, 0.242, places=3)388 self.assertEqual(tree[7].left, -7)389 self.assertEqual(tree[7].right, -1)390 self.assertAlmostEqual(tree[7].distance, 0.246, places=3)391 self.assertEqual(tree[8].left, 3)392 self.assertEqual(tree[8].right, -8)393 self.assertAlmostEqual(tree[8].distance, 0.287, places=3)394 self.assertEqual(tree[9].left, -9)395 self.assertEqual(tree[9].right, 8)396 self.assertAlmostEqual(tree[9].distance, 1.936, places=3)397 self.assertEqual(tree[10].left, -10)398 self.assertEqual(tree[10].right, -6)399 self.assertAlmostEqual(tree[10].distance, 3.432, places=3)400 self.assertEqual(tree[11].left, 6)401 self.assertEqual(tree[11].right, -11)402 self.assertAlmostEqual(tree[11].distance, 3.535, places=3)403 404 # Pairwise centroid-linkage clustering405 tree = treecluster(data=data2, mask=mask2, weight=weight2,406 transpose=0, method='c', dist='e')407 self.assertEqual(len(tree), len(data2)-1)408 self.assertEqual(tree[0].left, 4)409 self.assertEqual(tree[0].right, 5)410 self.assertAlmostEqual(tree[0].distance, 0.003, places=3)411 self.assertEqual(tree[1].left, 12)412 self.assertEqual(tree[1].right, 9)413 self.assertAlmostEqual(tree[1].distance, 0.029, places=3)414 self.assertEqual(tree[2].left, 1)415 self.assertEqual(tree[2].right, 2)416 self.assertAlmostEqual(tree[2].distance, 0.061, places=3)417 self.assertEqual(tree[3].left, -2)418 self.assertEqual(tree[3].right, 11)419 self.assertAlmostEqual(tree[3].distance, 0.063, places=3)420 self.assertEqual(tree[4].left, 10)421 self.assertEqual(tree[4].right, -4)422 self.assertAlmostEqual(tree[4].distance, 0.109, places=3)423 self.assertEqual(tree[5].left, -5)424 self.assertEqual(tree[5].right, 7)425 self.assertAlmostEqual(tree[5].distance, 0.189, places=3)426 self.assertEqual(tree[6].left, 0)427 self.assertEqual(tree[6].right, -3)428 self.assertAlmostEqual(tree[6].distance, 0.239, places=3)429 self.assertEqual(tree[7].left, 3)430 self.assertEqual(tree[7].right, -1)431 self.assertAlmostEqual(tree[7].distance, 0.390, places=3)432 self.assertEqual(tree[8].left, -7)433 self.assertEqual(tree[8].right, -8)434 self.assertAlmostEqual(tree[8].distance, 0.382, places=3)435 self.assertEqual(tree[9].left, -9)436 self.assertEqual(tree[9].right, 8)437 self.assertAlmostEqual(tree[9].distance, 3.063, places=3)438 self.assertEqual(tree[10].left, 6)439 self.assertEqual(tree[10].right, -6)440 self.assertAlmostEqual(tree[10].distance, 4.578, places=3)441 self.assertEqual(tree[11].left, -10)442 self.assertEqual(tree[11].right, -11)443 self.assertAlmostEqual(tree[11].distance, 11.536, places=3)444 445 # Pairwise maximum-linkage clustering446 tree = treecluster(data=data2, mask=mask2, weight=weight2,447 transpose=0, method='m', dist='e')448 self.assertEqual(len(tree), len(data2)-1)449 self.assertEqual(tree[0].left, 5)450 self.assertEqual(tree[0].right, 4)451 self.assertAlmostEqual(tree[0].distance, 0.003, places=3)452 self.assertEqual(tree[1].left, 9)453 self.assertEqual(tree[1].right, 12)454 self.assertAlmostEqual(tree[1].distance, 0.029, places=3)455 self.assertEqual(tree[2].left, 2)456 self.assertEqual(tree[2].right, 1)457 self.assertAlmostEqual(tree[2].distance, 0.061, places=3)458 self.assertEqual(tree[3].left, 11)459 self.assertEqual(tree[3].right, 10)460 self.assertAlmostEqual(tree[3].distance, 0.077, places=3)461 self.assertEqual(tree[4].left, -2)462 self.assertEqual(tree[4].right, -4)463 self.assertAlmostEqual(tree[4].distance, 0.216, places=3)464 self.assertEqual(tree[5].left, -3)465 self.assertEqual(tree[5].right, 0)466 self.assertAlmostEqual(tree[5].distance, 0.266, places=3)467 self.assertEqual(tree[6].left, -5)468 self.assertEqual(tree[6].right, 7)469 self.assertAlmostEqual(tree[6].distance, 0.302, places=3)470 self.assertEqual(tree[7].left, -1)471 self.assertEqual(tree[7].right, 3)472 self.assertAlmostEqual(tree[7].distance, 0.425, places=3)473 self.assertEqual(tree[8].left, -8)474 self.assertEqual(tree[8].right, -6)475 self.assertAlmostEqual(tree[8].distance, 0.968, places=3)476 self.assertEqual(tree[9].left, 8)477 self.assertEqual(tree[9].right, 6)478 self.assertAlmostEqual(tree[9].distance, 3.975, places=3)479 self.assertEqual(tree[10].left, -10)480 self.assertEqual(tree[10].right, -7)481 self.assertAlmostEqual(tree[10].distance, 5.755, places=3)482 self.assertEqual(tree[11].left, -11)483 self.assertEqual(tree[11].right, -9)484 self.assertAlmostEqual(tree[11].distance, 22.734, places=3)485 def test_somcluster(self):486 if TestCluster.module=='Bio.Cluster':487 from Bio.Cluster import somcluster488 elif TestCluster.module=='Pycluster':489 from Pycluster import somcluster490 # First data set491 weight = [ 1,1,1,1,1 ]492 data = numpy.array([[ 1.1, 2.2, 3.3, 4.4, 5.5], 493 [ 3.1, 3.2, 1.3, 2.4, 1.5], 494 [ 4.1, 2.2, 0.3, 5.4, 0.5], 495 [ 12.1, 2.0, 0.0, 5.0, 0.0]])496 mask = numpy.array([[ 1, 1, 1, 1, 1], 497 [ 1, 1, 1, 1, 1], 498 [ 1, 1, 1, 1, 1], 499 [ 1, 1, 1, 1, 1]], int)500 clusterid, celldata = somcluster(data=data, mask=mask, weight=weight,501 transpose=0, nxgrid=10, nygrid=10,502 inittau=0.02, niter=100, dist='e')503 self.assertEqual(len(clusterid), len(data))504 self.assertEqual(len(clusterid[0]), 2)505 # Second data set506 weight = [ 1,1 ]507 data = numpy.array([[ 1.1, 1.2 ],508 [ 1.4, 1.3 ],509 [ 1.1, 1.5 ],510 [ 2.0, 1.5 ],511 [ 1.7, 1.9 ],512 [ 1.7, 1.9 ],513 [ 5.7, 5.9 ],514 [ 5.7, 5.9 ],515 [ 3.1, 3.3 ],516 [ 5.4, 5.3 ],517 [ 5.1, 5.5 ],518 [ 5.0, 5.5 ],519 [ 5.1, 5.2 ]])520 mask = numpy.array([[ 1, 1 ],521 [ 1, 1 ],522 [ 1, 1 ],523 [ 1, 1 ],524 [ 1, 1 ],525 [ 1, 1 ],526 [ 1, 1 ],527 [ 1, 1 ],528 [ 1, 1 ],529 [ 1, 1 ],530 [ 1, 1 ],531 [ 1, 1 ],532 [ 1, 1 ]], int)533 clusterid, celldata = somcluster(data=data, mask=mask, weight=weight,534 transpose=0, nxgrid=10, nygrid=10,535 inittau=0.02, niter=100, dist='e')536 self.assertEqual(len(clusterid), len(data))537 self.assertEqual(len(clusterid[0]), 2)538 def test_distancematrix_kmedoids(self):539 if TestCluster.module=='Bio.Cluster':540 from Bio.Cluster import distancematrix, kmedoids541 elif TestCluster.module=='Pycluster':542 from Pycluster import distancematrix, kmedoids543 data = numpy.array([[2.2, 3.3, 4.4],544 [2.1, 1.4, 5.6],545 [7.8, 9.0, 1.2],546 [4.5, 2.3, 1.5],547 [4.2, 2.4, 1.9],548 [3.6, 3.1, 9.3],549 [2.3, 1.2, 3.9],550 [4.2, 9.6, 9.3],551 [1.7, 8.9, 1.1]])552 mask = numpy.array([[1, 1, 1],553 [1, 1, 1],554 [0, 1, 1],555 [1, 1, 1],556 [1, 1, 1],557 [0, 1, 0],558 [1, 1, 1],559 [1, 0, 1],560 [1, 1, 1]], int)561 weight = numpy.array([2.0, 1.0, 0.5])562 matrix = distancematrix(data, mask=mask, weight=weight)563 self.assertAlmostEqual(matrix[1][0], 1.243, places=3)564 self.assertAlmostEqual(matrix[2][0], 25.073, places=3)565 self.assertAlmostEqual(matrix[2][1], 44.960, places=3)566 self.assertAlmostEqual(matrix[3][0], 4.510, places=3)567 self.assertAlmostEqual(matrix[3][1], 5.924, places=3)568 self.assertAlmostEqual(matrix[3][2], 29.957, places=3)569 self.assertAlmostEqual(matrix[4][0], 3.410, places=3)570 self.assertAlmostEqual(matrix[4][1], 4.761, places=3)571 self.assertAlmostEqual(matrix[4][2], 29.203, places=3)572 self.assertAlmostEqual(matrix[4][3], 0.077, places=3)573 self.assertAlmostEqual(matrix[5][0], 0.040, places=3)574 self.assertAlmostEqual(matrix[5][1], 2.890, places=3)575 self.assertAlmostEqual(matrix[5][2], 34.810, places=3)576 self.assertAlmostEqual(matrix[5][3], 0.640, places=3)577 self.assertAlmostEqual(matrix[5][4], 0.490, places=3)578 self.assertAlmostEqual(matrix[6][0], 1.301, places=3)579 self.assertAlmostEqual(matrix[6][1], 0.447, places=3)580 self.assertAlmostEqual(matrix[6][2], 42.990, places=3)581 self.assertAlmostEqual(matrix[6][3], 3.934, places=3)582 self.assertAlmostEqual(matrix[6][4], 3.046, places=3)583 self.assertAlmostEqual(matrix[6][5], 3.610, places=3)584 self.assertAlmostEqual(matrix[7][0], 8.002, places=3)585 self.assertAlmostEqual(matrix[7][1], 6.266, places=3)586 self.assertAlmostEqual(matrix[7][2], 65.610, places=3)587 self.assertAlmostEqual(matrix[7][3], 12.240, places=3)588 self.assertAlmostEqual(matrix[7][4], 10.952, places=3)589 self.assertAlmostEqual(matrix[7][5], 0.000, places=3)590 self.assertAlmostEqual(matrix[7][6], 8.720, places=3)591 self.assertAlmostEqual(matrix[8][0], 10.659, places=3)592 self.assertAlmostEqual(matrix[8][1], 19.056, places=3)593 self.assertAlmostEqual(matrix[8][2], 0.010, places=3)594 self.assertAlmostEqual(matrix[8][3], 16.949, places=3)595 self.assertAlmostEqual(matrix[8][4], 15.734, places=3)596 self.assertAlmostEqual(matrix[8][5], 33.640, places=3)597 self.assertAlmostEqual(matrix[8][6], 18.266, places=3)598 self.assertAlmostEqual(matrix[8][7], 18.448, places=3)599 clusterid, error, nfound = kmedoids(matrix, npass=1000)600 self.assertEqual(clusterid[0], 5)601 self.assertEqual(clusterid[1], 5)602 self.assertEqual(clusterid[2], 2)603 self.assertEqual(clusterid[3], 5)604 self.assertEqual(clusterid[4], 5)605 self.assertEqual(clusterid[5], 5)606 self.assertEqual(clusterid[6], 5)607 self.assertEqual(clusterid[7], 5)608 self.assertEqual(clusterid[8], 2)609 self.assertAlmostEqual(error, 7.680, places=3)610 def test_pca(self):611 if TestCluster.module=='Bio.Cluster':612 from Bio.Cluster import pca613 elif TestCluster.module=='Pycluster':614 from Pycluster import pca615 data = numpy.array([[ 3.1, 1.2 ],616 [ 1.4, 1.3 ],617 [ 1.1, 1.5 ],618 [ 2.0, 1.5 ],619 [ 1.7, 1.9 ],620 [ 1.7, 1.9 ],621 [ 5.7, 5.9 ],622 [ 5.7, 5.9 ],623 [ 3.1, 3.3 ],624 [ 5.4, 5.3 ],625 [ 5.1, 5.5 ],626 [ 5.0, 5.5 ],627 [ 5.1, 5.2 ],628 ])629 mean, coordinates, pc, eigenvalues = pca(data)630 self.assertAlmostEqual(mean[0], 3.5461538461538464)631 self.assertAlmostEqual(mean[1], 3.5307692307692311)632 self.assertAlmostEqual(coordinates[0,0], 2.0323189722653883)633 self.assertAlmostEqual(coordinates[0,1], 1.2252420399694917)634 self.assertAlmostEqual(coordinates[1,0], 3.0936985166252251)635 self.assertAlmostEqual(coordinates[1,1], -0.10647619705157851)636 self.assertAlmostEqual(coordinates[2,0], 3.1453186907749426)637 self.assertAlmostEqual(coordinates[2,1], -0.46331699855941139)638 self.assertAlmostEqual(coordinates[3,0], 2.5440202962223761)639 self.assertAlmostEqual(coordinates[3,1], 0.20633980959571077)640 self.assertAlmostEqual(coordinates[4,0], 2.4468278463376221)641 self.assertAlmostEqual(coordinates[4,1], -0.28412285736824866)642 self.assertAlmostEqual(coordinates[5,0], 2.4468278463376221)643 self.assertAlmostEqual(coordinates[5,1], -0.28412285736824866)644 self.assertAlmostEqual(coordinates[6,0], -3.2018619434743254)645 self.assertAlmostEqual(coordinates[6,1], 0.019692314198662915)646 self.assertAlmostEqual(coordinates[7,0], -3.2018619434743254)647 self.assertAlmostEqual(coordinates[7,1], 0.019692314198662915)648 self.assertAlmostEqual(coordinates[8,0], 0.46978641990344067)649 self.assertAlmostEqual(coordinates[8,1], -0.17778754731982949)650 self.assertAlmostEqual(coordinates[9,0], -2.5549912731867215)651 self.assertAlmostEqual(coordinates[9,1], 0.19733897451533403)652 self.assertAlmostEqual(coordinates[10,0], -2.5033710990370044)653 self.assertAlmostEqual(coordinates[10,1], -0.15950182699250004)654 self.assertAlmostEqual(coordinates[11,0], -2.4365601663089413)655 self.assertAlmostEqual(coordinates[11,1], -0.23390813900973562)656 self.assertAlmostEqual(coordinates[12,0], -2.2801521629852974)657 self.assertAlmostEqual(coordinates[12,1], 0.0409309711916888)658 self.assertAlmostEqual(pc[0,0], -0.66810932728062988)659 self.assertAlmostEqual(pc[0,1], -0.74406312017235743)660 self.assertAlmostEqual(pc[1,0], 0.74406312017235743)661 self.assertAlmostEqual(pc[1,1], -0.66810932728062988)662 self.assertAlmostEqual(eigenvalues[0], 9.3110471246032844)663 self.assertAlmostEqual(eigenvalues[1], 1.4437456297481428)664 data = numpy.array([[ 2.3, 4.5, 1.2, 6.7, 5.3, 7.1],665 [ 1.3, 6.5, 2.2, 5.7, 6.2, 9.1],666 [ 3.2, 7.2, 3.2, 7.4, 7.3, 8.9],667 [ 4.2, 5.2, 9.2, 4.4, 6.3, 7.2]])668 mean, coordinates, pc, eigenvalues = pca(data)669 self.assertAlmostEqual(mean[0], 2.7500)670 self.assertAlmostEqual(mean[1], 5.8500)671 self.assertAlmostEqual(mean[2], 3.9500)672 self.assertAlmostEqual(mean[3], 6.0500)673 self.assertAlmostEqual(mean[4], 6.2750)674 self.assertAlmostEqual(mean[5], 8.0750)675 self.assertAlmostEqual(coordinates[0,0], 2.6460846688406905)676 self.assertAlmostEqual(coordinates[0,1], -2.1421701432732418)677 self.assertAlmostEqual(coordinates[0,2], -0.56620932754145858)678 self.assertAlmostEqual(coordinates[0,3], 0.0)679 self.assertAlmostEqual(coordinates[1,0], 2.0644120899917544)680 self.assertAlmostEqual(coordinates[1,1], 0.55542108669180323)681 self.assertAlmostEqual(coordinates[1,2], 1.4818772348457117)682 self.assertAlmostEqual(coordinates[1,3], 0.0)683 self.assertAlmostEqual(coordinates[2,0], 1.0686641862092987)684 self.assertAlmostEqual(coordinates[2,1], 1.9994412069101073)685 self.assertAlmostEqual(coordinates[2,2], -1.000720598980291)686 self.assertAlmostEqual(coordinates[2,3], 0.0)687 self.assertAlmostEqual(coordinates[3,0], -5.77916094504174)688 self.assertAlmostEqual(coordinates[3,1], -0.41269215032867046)689 self.assertAlmostEqual(coordinates[3,2], 0.085052691676038017)690 self.assertAlmostEqual(coordinates[3,3], 0.0)691 self.assertAlmostEqual(pc[0,0], -0.26379660005997291)692 self.assertAlmostEqual(pc[0,1], 0.064814972617134495)693 self.assertAlmostEqual(pc[0,2], -0.91763310094893846)694 self.assertAlmostEqual(pc[0,3], 0.26145408875373249)695 self.assertAlmostEqual(pc[1,0], 0.05073770520434398)696 self.assertAlmostEqual(pc[1,1], 0.68616983388698793)697 self.assertAlmostEqual(pc[1,2], 0.13819106187213354)698 self.assertAlmostEqual(pc[1,3], 0.19782544121828985)699 self.assertAlmostEqual(pc[2,0], -0.63000893660095947)700 self.assertAlmostEqual(pc[2,1], 0.091155993862151397)701 self.assertAlmostEqual(pc[2,2], 0.045630391256086845)702 self.assertAlmostEqual(pc[2,3], -0.67456694780914772)703 # As the last eigenvalue is zero, the corresponding eigenvector is704 # strongly affected by roundoff error, and is not being tested here.705 # For PCA, this doesn't matter since all data have a zero coefficient706 # along this eigenvector.707 self.assertAlmostEqual(eigenvalues[0], 6.7678878332578778)708 self.assertAlmostEqual(eigenvalues[1], 3.0108911400291856)709 self.assertAlmostEqual(eigenvalues[2], 1.8775592718563467)710 self.assertAlmostEqual(eigenvalues[3], 0.0)711if __name__ == "__main__":712 TestCluster.module = 'Bio.Cluster'713 runner = unittest.TextTestRunner(verbosity = 2)...

Full Screen

Full Screen

validAttr.test.js

Source:validAttr.test.js Github

copy

Full Screen

1// @flow2import validAttr from '../validAttr'3describe('validAttr', () => {4 it('should allow all the reactProps', () => {5 expect(validAttr('children')).toEqual(true)6 expect(validAttr('dangerouslySetInnerHTML')).toEqual(true)7 expect(validAttr('key')).toEqual(true)8 expect(validAttr('ref')).toEqual(true)9 expect(validAttr('autoFocus')).toEqual(true)10 expect(validAttr('defaultValue')).toEqual(true)11 expect(validAttr('valueLink')).toEqual(true)12 expect(validAttr('defaultChecked')).toEqual(true)13 expect(validAttr('checkedLink')).toEqual(true)14 expect(validAttr('innerHTML')).toEqual(true)15 expect(validAttr('suppressContentEditableWarning')).toEqual(true)16 expect(validAttr('onFocusIn')).toEqual(true)17 expect(validAttr('onFocusOut')).toEqual(true)18 expect(validAttr('className')).toEqual(true)19 })20 it('should allow all the html props', () => {21 expect(validAttr('accept')).toEqual(true)22 expect(validAttr('acceptCharset')).toEqual(true)23 expect(validAttr('accessKey')).toEqual(true)24 expect(validAttr('action')).toEqual(true)25 expect(validAttr('allowFullScreen')).toEqual(true)26 expect(validAttr('allowTransparency')).toEqual(true)27 expect(validAttr('alt')).toEqual(true)28 expect(validAttr('async')).toEqual(true)29 expect(validAttr('autoComplete')).toEqual(true)30 expect(validAttr('autoPlay')).toEqual(true)31 expect(validAttr('capture')).toEqual(true)32 expect(validAttr('cellPadding')).toEqual(true)33 expect(validAttr('cellSpacing')).toEqual(true)34 expect(validAttr('charSet')).toEqual(true)35 expect(validAttr('challenge')).toEqual(true)36 expect(validAttr('checked')).toEqual(true)37 expect(validAttr('cite')).toEqual(true)38 expect(validAttr('classID')).toEqual(true)39 expect(validAttr('className')).toEqual(true)40 expect(validAttr('cols')).toEqual(true)41 expect(validAttr('colSpan')).toEqual(true)42 expect(validAttr('content')).toEqual(true)43 expect(validAttr('contentEditable')).toEqual(true)44 expect(validAttr('contextMenu')).toEqual(true)45 expect(validAttr('controls')).toEqual(true)46 expect(validAttr('controlsList')).toEqual(true)47 expect(validAttr('coords')).toEqual(true)48 expect(validAttr('crossOrigin')).toEqual(true)49 expect(validAttr('data')).toEqual(true)50 expect(validAttr('dateTime')).toEqual(true)51 expect(validAttr('default')).toEqual(true)52 expect(validAttr('defer')).toEqual(true)53 expect(validAttr('dir')).toEqual(true)54 expect(validAttr('disabled')).toEqual(true)55 expect(validAttr('download')).toEqual(true)56 expect(validAttr('draggable')).toEqual(true)57 expect(validAttr('encType')).toEqual(true)58 expect(validAttr('form')).toEqual(true)59 expect(validAttr('formAction')).toEqual(true)60 expect(validAttr('formEncType')).toEqual(true)61 expect(validAttr('formMethod')).toEqual(true)62 expect(validAttr('formNoValidate')).toEqual(true)63 expect(validAttr('formTarget')).toEqual(true)64 expect(validAttr('frameBorder')).toEqual(true)65 expect(validAttr('headers')).toEqual(true)66 expect(validAttr('height')).toEqual(true)67 expect(validAttr('hidden')).toEqual(true)68 expect(validAttr('high')).toEqual(true)69 expect(validAttr('href')).toEqual(true)70 expect(validAttr('hrefLang')).toEqual(true)71 expect(validAttr('htmlFor')).toEqual(true)72 expect(validAttr('httpEquiv')).toEqual(true)73 expect(validAttr('icon')).toEqual(true)74 expect(validAttr('id')).toEqual(true)75 expect(validAttr('inputMode')).toEqual(true)76 expect(validAttr('integrity')).toEqual(true)77 expect(validAttr('is')).toEqual(true)78 expect(validAttr('keyParams')).toEqual(true)79 expect(validAttr('keyType')).toEqual(true)80 expect(validAttr('kind')).toEqual(true)81 expect(validAttr('label')).toEqual(true)82 expect(validAttr('lang')).toEqual(true)83 expect(validAttr('list')).toEqual(true)84 expect(validAttr('loop')).toEqual(true)85 expect(validAttr('low')).toEqual(true)86 expect(validAttr('manifest')).toEqual(true)87 expect(validAttr('marginHeight')).toEqual(true)88 expect(validAttr('marginWidth')).toEqual(true)89 expect(validAttr('max')).toEqual(true)90 expect(validAttr('maxLength')).toEqual(true)91 expect(validAttr('media')).toEqual(true)92 expect(validAttr('mediaGroup')).toEqual(true)93 expect(validAttr('method')).toEqual(true)94 expect(validAttr('min')).toEqual(true)95 expect(validAttr('minLength')).toEqual(true)96 expect(validAttr('multiple')).toEqual(true)97 expect(validAttr('muted')).toEqual(true)98 expect(validAttr('name')).toEqual(true)99 expect(validAttr('nonce')).toEqual(true)100 expect(validAttr('noValidate')).toEqual(true)101 expect(validAttr('open')).toEqual(true)102 expect(validAttr('optimum')).toEqual(true)103 expect(validAttr('pattern')).toEqual(true)104 expect(validAttr('placeholder')).toEqual(true)105 expect(validAttr('poster')).toEqual(true)106 expect(validAttr('preload')).toEqual(true)107 expect(validAttr('profile')).toEqual(true)108 expect(validAttr('radioGroup')).toEqual(true)109 expect(validAttr('readOnly')).toEqual(true)110 expect(validAttr('referrerPolicy')).toEqual(true)111 expect(validAttr('rel')).toEqual(true)112 expect(validAttr('required')).toEqual(true)113 expect(validAttr('reversed')).toEqual(true)114 expect(validAttr('role')).toEqual(true)115 expect(validAttr('rows')).toEqual(true)116 expect(validAttr('rowSpan')).toEqual(true)117 expect(validAttr('sandbox')).toEqual(true)118 expect(validAttr('scope')).toEqual(true)119 expect(validAttr('scoped')).toEqual(true)120 expect(validAttr('scrolling')).toEqual(true)121 expect(validAttr('seamless')).toEqual(true)122 expect(validAttr('selected')).toEqual(true)123 expect(validAttr('shape')).toEqual(true)124 expect(validAttr('size')).toEqual(true)125 expect(validAttr('sizes')).toEqual(true)126 expect(validAttr('span')).toEqual(true)127 expect(validAttr('spellCheck')).toEqual(true)128 expect(validAttr('src')).toEqual(true)129 expect(validAttr('srcDoc')).toEqual(true)130 expect(validAttr('srcLang')).toEqual(true)131 expect(validAttr('srcSet')).toEqual(true)132 expect(validAttr('start')).toEqual(true)133 expect(validAttr('step')).toEqual(true)134 expect(validAttr('style')).toEqual(true)135 expect(validAttr('summary')).toEqual(true)136 expect(validAttr('tabIndex')).toEqual(true)137 expect(validAttr('target')).toEqual(true)138 expect(validAttr('title')).toEqual(true)139 expect(validAttr('type')).toEqual(true)140 expect(validAttr('useMap')).toEqual(true)141 expect(validAttr('value')).toEqual(true)142 expect(validAttr('width')).toEqual(true)143 expect(validAttr('wmode')).toEqual(true)144 expect(validAttr('wrap')).toEqual(true)145 expect(validAttr('about')).toEqual(true)146 expect(validAttr('datatype')).toEqual(true)147 expect(validAttr('inlist')).toEqual(true)148 expect(validAttr('prefix')).toEqual(true)149 expect(validAttr('property')).toEqual(true)150 expect(validAttr('resource')).toEqual(true)151 expect(validAttr('typeof')).toEqual(true)152 expect(validAttr('vocab')).toEqual(true)153 expect(validAttr('autoCapitalize')).toEqual(true)154 expect(validAttr('autoCorrect')).toEqual(true)155 expect(validAttr('autoSave')).toEqual(true)156 expect(validAttr('color')).toEqual(true)157 expect(validAttr('itemProp')).toEqual(true)158 expect(validAttr('itemScope')).toEqual(true)159 expect(validAttr('itemType')).toEqual(true)160 expect(validAttr('itemID')).toEqual(true)161 expect(validAttr('itemRef')).toEqual(true)162 expect(validAttr('results')).toEqual(true)163 expect(validAttr('security')).toEqual(true)164 expect(validAttr('unselectable')).toEqual(true)165 })166 it('should handle all the SVG props', () => {167 expect(validAttr('accentHeight')).toEqual(true)168 expect(validAttr('accumulate')).toEqual(true)169 expect(validAttr('additive')).toEqual(true)170 expect(validAttr('alignmentBaseline')).toEqual(true)171 expect(validAttr('allowReorder')).toEqual(true)172 expect(validAttr('alphabetic')).toEqual(true)173 expect(validAttr('amplitude')).toEqual(true)174 expect(validAttr('arabicForm')).toEqual(true)175 expect(validAttr('ascent')).toEqual(true)176 expect(validAttr('attributeName')).toEqual(true)177 expect(validAttr('attributeType')).toEqual(true)178 expect(validAttr('autoReverse')).toEqual(true)179 expect(validAttr('azimuth')).toEqual(true)180 expect(validAttr('baseFrequency')).toEqual(true)181 expect(validAttr('baseProfile')).toEqual(true)182 expect(validAttr('baselineShift')).toEqual(true)183 expect(validAttr('bbox')).toEqual(true)184 expect(validAttr('begin')).toEqual(true)185 expect(validAttr('bias')).toEqual(true)186 expect(validAttr('by')).toEqual(true)187 expect(validAttr('calcMode')).toEqual(true)188 expect(validAttr('capHeight')).toEqual(true)189 expect(validAttr('clip')).toEqual(true)190 expect(validAttr('clipPath')).toEqual(true)191 expect(validAttr('clipRule')).toEqual(true)192 expect(validAttr('clipPathUnits')).toEqual(true)193 expect(validAttr('colorInterpolation')).toEqual(true)194 expect(validAttr('colorInterpolationFilters')).toEqual(true)195 expect(validAttr('colorProfile')).toEqual(true)196 expect(validAttr('colorRendering')).toEqual(true)197 expect(validAttr('contentScriptType')).toEqual(true)198 expect(validAttr('contentStyleType')).toEqual(true)199 expect(validAttr('cursor')).toEqual(true)200 expect(validAttr('cx')).toEqual(true)201 expect(validAttr('cy')).toEqual(true)202 expect(validAttr('d')).toEqual(true)203 expect(validAttr('decelerate')).toEqual(true)204 expect(validAttr('descent')).toEqual(true)205 expect(validAttr('diffuseConstant')).toEqual(true)206 expect(validAttr('direction')).toEqual(true)207 expect(validAttr('display')).toEqual(true)208 expect(validAttr('divisor')).toEqual(true)209 expect(validAttr('dominantBaseline')).toEqual(true)210 expect(validAttr('dur')).toEqual(true)211 expect(validAttr('dx')).toEqual(true)212 expect(validAttr('dy')).toEqual(true)213 expect(validAttr('edgeMode')).toEqual(true)214 expect(validAttr('elevation')).toEqual(true)215 expect(validAttr('enableBackground')).toEqual(true)216 expect(validAttr('end')).toEqual(true)217 expect(validAttr('exponent')).toEqual(true)218 expect(validAttr('externalResourcesRequired')).toEqual(true)219 expect(validAttr('fill')).toEqual(true)220 expect(validAttr('fillOpacity')).toEqual(true)221 expect(validAttr('fillRule')).toEqual(true)222 expect(validAttr('filter')).toEqual(true)223 expect(validAttr('filterRes')).toEqual(true)224 expect(validAttr('filterUnits')).toEqual(true)225 expect(validAttr('floodColor')).toEqual(true)226 expect(validAttr('floodOpacity')).toEqual(true)227 expect(validAttr('focusable')).toEqual(true)228 expect(validAttr('fontFamily')).toEqual(true)229 expect(validAttr('fontSize')).toEqual(true)230 expect(validAttr('fontSizeAdjust')).toEqual(true)231 expect(validAttr('fontStretch')).toEqual(true)232 expect(validAttr('fontStyle')).toEqual(true)233 expect(validAttr('fontVariant')).toEqual(true)234 expect(validAttr('fontWeight')).toEqual(true)235 expect(validAttr('format')).toEqual(true)236 expect(validAttr('from')).toEqual(true)237 expect(validAttr('fx')).toEqual(true)238 expect(validAttr('fy')).toEqual(true)239 expect(validAttr('g1')).toEqual(true)240 expect(validAttr('g2')).toEqual(true)241 expect(validAttr('glyphName')).toEqual(true)242 expect(validAttr('glyphOrientationHorizontal')).toEqual(true)243 expect(validAttr('glyphOrientationVertical')).toEqual(true)244 expect(validAttr('glyphRef')).toEqual(true)245 expect(validAttr('gradientTransform')).toEqual(true)246 expect(validAttr('gradientUnits')).toEqual(true)247 expect(validAttr('hanging')).toEqual(true)248 expect(validAttr('horizAdvX')).toEqual(true)249 expect(validAttr('horizOriginX')).toEqual(true)250 expect(validAttr('ideographic')).toEqual(true)251 expect(validAttr('imageRendering')).toEqual(true)252 expect(validAttr('in')).toEqual(true)253 expect(validAttr('in2')).toEqual(true)254 expect(validAttr('intercept')).toEqual(true)255 expect(validAttr('k')).toEqual(true)256 expect(validAttr('k1')).toEqual(true)257 expect(validAttr('k2')).toEqual(true)258 expect(validAttr('k3')).toEqual(true)259 expect(validAttr('k4')).toEqual(true)260 expect(validAttr('kernelMatrix')).toEqual(true)261 expect(validAttr('kernelUnitLength')).toEqual(true)262 expect(validAttr('kerning')).toEqual(true)263 expect(validAttr('keyPoints')).toEqual(true)264 expect(validAttr('keySplines')).toEqual(true)265 expect(validAttr('keyTimes')).toEqual(true)266 expect(validAttr('lengthAdjust')).toEqual(true)267 expect(validAttr('letterSpacing')).toEqual(true)268 expect(validAttr('lightingColor')).toEqual(true)269 expect(validAttr('limitingConeAngle')).toEqual(true)270 expect(validAttr('local')).toEqual(true)271 expect(validAttr('markerEnd')).toEqual(true)272 expect(validAttr('markerMid')).toEqual(true)273 expect(validAttr('markerStart')).toEqual(true)274 expect(validAttr('markerHeight')).toEqual(true)275 expect(validAttr('markerUnits')).toEqual(true)276 expect(validAttr('markerWidth')).toEqual(true)277 expect(validAttr('mask')).toEqual(true)278 expect(validAttr('maskContentUnits')).toEqual(true)279 expect(validAttr('maskUnits')).toEqual(true)280 expect(validAttr('mathematical')).toEqual(true)281 expect(validAttr('mode')).toEqual(true)282 expect(validAttr('numOctaves')).toEqual(true)283 expect(validAttr('offset')).toEqual(true)284 expect(validAttr('opacity')).toEqual(true)285 expect(validAttr('operator')).toEqual(true)286 expect(validAttr('order')).toEqual(true)287 expect(validAttr('orient')).toEqual(true)288 expect(validAttr('orientation')).toEqual(true)289 expect(validAttr('origin')).toEqual(true)290 expect(validAttr('overflow')).toEqual(true)291 expect(validAttr('overlinePosition')).toEqual(true)292 expect(validAttr('overlineThickness')).toEqual(true)293 expect(validAttr('paintOrder')).toEqual(true)294 expect(validAttr('panose1')).toEqual(true)295 expect(validAttr('pathLength')).toEqual(true)296 expect(validAttr('patternContentUnits')).toEqual(true)297 expect(validAttr('patternTransform')).toEqual(true)298 expect(validAttr('patternUnits')).toEqual(true)299 expect(validAttr('pointerEvents')).toEqual(true)300 expect(validAttr('points')).toEqual(true)301 expect(validAttr('pointsAtX')).toEqual(true)302 expect(validAttr('pointsAtY')).toEqual(true)303 expect(validAttr('pointsAtZ')).toEqual(true)304 expect(validAttr('preserveAlpha')).toEqual(true)305 expect(validAttr('preserveAspectRatio')).toEqual(true)306 expect(validAttr('primitiveUnits')).toEqual(true)307 expect(validAttr('r')).toEqual(true)308 expect(validAttr('radius')).toEqual(true)309 expect(validAttr('refX')).toEqual(true)310 expect(validAttr('refY')).toEqual(true)311 expect(validAttr('renderingIntent')).toEqual(true)312 expect(validAttr('repeatCount')).toEqual(true)313 expect(validAttr('repeatDur')).toEqual(true)314 expect(validAttr('requiredExtensions')).toEqual(true)315 expect(validAttr('requiredFeatures')).toEqual(true)316 expect(validAttr('restart')).toEqual(true)317 expect(validAttr('result')).toEqual(true)318 expect(validAttr('rotate')).toEqual(true)319 expect(validAttr('rx')).toEqual(true)320 expect(validAttr('ry')).toEqual(true)321 expect(validAttr('scale')).toEqual(true)322 expect(validAttr('seed')).toEqual(true)323 expect(validAttr('shapeRendering')).toEqual(true)324 expect(validAttr('slope')).toEqual(true)325 expect(validAttr('spacing')).toEqual(true)326 expect(validAttr('specularConstant')).toEqual(true)327 expect(validAttr('specularExponent')).toEqual(true)328 expect(validAttr('speed')).toEqual(true)329 expect(validAttr('spreadMethod')).toEqual(true)330 expect(validAttr('startOffset')).toEqual(true)331 expect(validAttr('stdDeviation')).toEqual(true)332 expect(validAttr('stemh')).toEqual(true)333 expect(validAttr('stemv')).toEqual(true)334 expect(validAttr('stitchTiles')).toEqual(true)335 expect(validAttr('stopColor')).toEqual(true)336 expect(validAttr('stopOpacity')).toEqual(true)337 expect(validAttr('strikethroughPosition')).toEqual(true)338 expect(validAttr('strikethroughThickness')).toEqual(true)339 expect(validAttr('string')).toEqual(true)340 expect(validAttr('stroke')).toEqual(true)341 expect(validAttr('strokeDasharray')).toEqual(true)342 expect(validAttr('strokeDashoffset')).toEqual(true)343 expect(validAttr('strokeLinecap')).toEqual(true)344 expect(validAttr('strokeLinejoin')).toEqual(true)345 expect(validAttr('strokeMiterlimit')).toEqual(true)346 expect(validAttr('strokeOpacity')).toEqual(true)347 expect(validAttr('strokeWidth')).toEqual(true)348 expect(validAttr('surfaceScale')).toEqual(true)349 expect(validAttr('systemLanguage')).toEqual(true)350 expect(validAttr('tableValues')).toEqual(true)351 expect(validAttr('targetX')).toEqual(true)352 expect(validAttr('targetY')).toEqual(true)353 expect(validAttr('textAnchor')).toEqual(true)354 expect(validAttr('textDecoration')).toEqual(true)355 expect(validAttr('textRendering')).toEqual(true)356 expect(validAttr('textLength')).toEqual(true)357 expect(validAttr('to')).toEqual(true)358 expect(validAttr('transform')).toEqual(true)359 expect(validAttr('u1')).toEqual(true)360 expect(validAttr('u2')).toEqual(true)361 expect(validAttr('underlinePosition')).toEqual(true)362 expect(validAttr('underlineThickness')).toEqual(true)363 expect(validAttr('unicode')).toEqual(true)364 expect(validAttr('unicodeBidi')).toEqual(true)365 expect(validAttr('unicodeRange')).toEqual(true)366 expect(validAttr('unitsPerEm')).toEqual(true)367 expect(validAttr('vAlphabetic')).toEqual(true)368 expect(validAttr('vHanging')).toEqual(true)369 expect(validAttr('vIdeographic')).toEqual(true)370 expect(validAttr('vMathematical')).toEqual(true)371 expect(validAttr('values')).toEqual(true)372 expect(validAttr('vectorEffect')).toEqual(true)373 expect(validAttr('version')).toEqual(true)374 expect(validAttr('vertAdvY')).toEqual(true)375 expect(validAttr('vertOriginX')).toEqual(true)376 expect(validAttr('vertOriginY')).toEqual(true)377 expect(validAttr('viewBox')).toEqual(true)378 expect(validAttr('viewTarget')).toEqual(true)379 expect(validAttr('visibility')).toEqual(true)380 expect(validAttr('widths')).toEqual(true)381 expect(validAttr('wordSpacing')).toEqual(true)382 expect(validAttr('writingMode')).toEqual(true)383 expect(validAttr('x')).toEqual(true)384 expect(validAttr('xHeight')).toEqual(true)385 expect(validAttr('x1')).toEqual(true)386 expect(validAttr('x2')).toEqual(true)387 expect(validAttr('xChannelSelector')).toEqual(true)388 expect(validAttr('xlinkActuate')).toEqual(true)389 expect(validAttr('xlinkArcrole')).toEqual(true)390 expect(validAttr('xlinkHref')).toEqual(true)391 expect(validAttr('xlinkRole')).toEqual(true)392 expect(validAttr('xlinkShow')).toEqual(true)393 expect(validAttr('xlinkTitle')).toEqual(true)394 expect(validAttr('xlinkType')).toEqual(true)395 expect(validAttr('xmlBase')).toEqual(true)396 expect(validAttr('xmlns')).toEqual(true)397 expect(validAttr('xmlnsXlink')).toEqual(true)398 expect(validAttr('xmlLang')).toEqual(true)399 expect(validAttr('xmlSpace')).toEqual(true)400 expect(validAttr('y')).toEqual(true)401 expect(validAttr('y1')).toEqual(true)402 expect(validAttr('y2')).toEqual(true)403 expect(validAttr('yChannelSelector')).toEqual(true)404 expect(validAttr('z')).toEqual(true)405 expect(validAttr('zoomAndPan')).toEqual(true)406 })407 it('should handle aria and data attributes', () => {408 expect(validAttr('data-xyz')).toEqual(true)409 expect(validAttr('data-omg-this-works')).toEqual(true)410 expect(validAttr('aria-label')).toEqual(true)411 expect(validAttr('aria-labelled-by')).toEqual(true)412 })413 it('should handle uppercase aria and data attributes', () => {414 expect(validAttr('DATA-XYZ')).toEqual(true)415 expect(validAttr('DATA-OMG-THIS-WORKS')).toEqual(true)416 expect(validAttr('ARIA-LABEL')).toEqual(true)417 expect(validAttr('ARIA-LABELLED-BY')).toEqual(true)418 })419 it('should allow all the event handlers', () => {420 expect(validAttr('onCopy')).toEqual(true)421 expect(validAttr('onCopyCapture')).toEqual(true)422 expect(validAttr('onCut')).toEqual(true)423 expect(validAttr('onCutCapture')).toEqual(true)424 expect(validAttr('onPaste')).toEqual(true)425 expect(validAttr('onPasteCapture')).toEqual(true)426 expect(validAttr('onCompositionEnd')).toEqual(true)427 expect(validAttr('onCompositionEndCapture')).toEqual(true)428 expect(validAttr('onCompositionStart')).toEqual(true)429 expect(validAttr('onCompositionStartCapture')).toEqual(true)430 expect(validAttr('onCompositionUpdate')).toEqual(true)431 expect(validAttr('onCompositionUpdateCapture')).toEqual(true)432 expect(validAttr('onKeyDown')).toEqual(true)433 expect(validAttr('onKeyDownCapture')).toEqual(true)434 expect(validAttr('onKeyPress')).toEqual(true)435 expect(validAttr('onKeyPressCapture')).toEqual(true)436 expect(validAttr('onKeyUp')).toEqual(true)437 expect(validAttr('onKeyUpCapture')).toEqual(true)438 expect(validAttr('onFocus')).toEqual(true)439 expect(validAttr('onFocusCapture')).toEqual(true)440 expect(validAttr('onBlur')).toEqual(true)441 expect(validAttr('onInvalid')).toEqual(true)442 expect(validAttr('onBlurCapture')).toEqual(true)443 expect(validAttr('onChange')).toEqual(true)444 expect(validAttr('onChangeCapture')).toEqual(true)445 expect(validAttr('onInput')).toEqual(true)446 expect(validAttr('onInputCapture')).toEqual(true)447 expect(validAttr('onSubmit')).toEqual(true)448 expect(validAttr('onSubmitCapture')).toEqual(true)449 expect(validAttr('onReset')).toEqual(true)450 expect(validAttr('onResetCapture')).toEqual(true)451 expect(validAttr('onClick')).toEqual(true)452 expect(validAttr('onClickCapture')).toEqual(true)453 expect(validAttr('onContextMenu')).toEqual(true)454 expect(validAttr('onContextMenuCapture')).toEqual(true)455 expect(validAttr('onDoubleClick')).toEqual(true)456 expect(validAttr('onDoubleClickCapture')).toEqual(true)457 expect(validAttr('onDrag')).toEqual(true)458 expect(validAttr('onDragCapture')).toEqual(true)459 expect(validAttr('onDragEnd')).toEqual(true)460 expect(validAttr('onDragEndCapture')).toEqual(true)461 expect(validAttr('onDragEnter')).toEqual(true)462 expect(validAttr('onDragEnterCapture')).toEqual(true)463 expect(validAttr('onDragExit')).toEqual(true)464 expect(validAttr('onDragExitCapture')).toEqual(true)465 expect(validAttr('onDragLeave')).toEqual(true)466 expect(validAttr('onDragLeaveCapture')).toEqual(true)467 expect(validAttr('onDragOver')).toEqual(true)468 expect(validAttr('onDragOverCapture')).toEqual(true)469 expect(validAttr('onDragStart')).toEqual(true)470 expect(validAttr('onDragStartCapture')).toEqual(true)471 expect(validAttr('onDrop')).toEqual(true)472 expect(validAttr('onDropCapture')).toEqual(true)473 expect(validAttr('onMouseDown')).toEqual(true)474 expect(validAttr('onMouseDownCapture')).toEqual(true)475 expect(validAttr('onMouseEnter')).toEqual(true)476 expect(validAttr('onMouseEnterCapture')).toEqual(true)477 expect(validAttr('onMouseLeave')).toEqual(true)478 expect(validAttr('onMouseLeaveCapture')).toEqual(true)479 expect(validAttr('onMouseMove')).toEqual(true)480 expect(validAttr('onMouseMoveCapture')).toEqual(true)481 expect(validAttr('onMouseOut')).toEqual(true)482 expect(validAttr('onMouseOutCapture')).toEqual(true)483 expect(validAttr('onMouseOver')).toEqual(true)484 expect(validAttr('onMouseOverCapture')).toEqual(true)485 expect(validAttr('onMouseUp')).toEqual(true)486 expect(validAttr('onMouseUpCapture')).toEqual(true)487 expect(validAttr('onSelect')).toEqual(true)488 expect(validAttr('onSelectCapture')).toEqual(true)489 expect(validAttr('onTouchCancel')).toEqual(true)490 expect(validAttr('onTouchCancelCapture')).toEqual(true)491 expect(validAttr('onTouchEnd')).toEqual(true)492 expect(validAttr('onTouchEndCapture')).toEqual(true)493 expect(validAttr('onTouchMove')).toEqual(true)494 expect(validAttr('onTouchMoveCapture')).toEqual(true)495 expect(validAttr('onTouchStart')).toEqual(true)496 expect(validAttr('onTouchStartCapture')).toEqual(true)497 expect(validAttr('onScroll')).toEqual(true)498 expect(validAttr('onScrollCapture')).toEqual(true)499 expect(validAttr('onWheel')).toEqual(true)500 expect(validAttr('onWheelCapture')).toEqual(true)501 expect(validAttr('onAbort')).toEqual(true)502 expect(validAttr('onAbortCapture')).toEqual(true)503 expect(validAttr('onCanPlay')).toEqual(true)504 expect(validAttr('onCanPlayCapture')).toEqual(true)505 expect(validAttr('onCanPlayThrough')).toEqual(true)506 expect(validAttr('onCanPlayThroughCapture')).toEqual(true)507 expect(validAttr('onDurationChange')).toEqual(true)508 expect(validAttr('onDurationChangeCapture')).toEqual(true)509 expect(validAttr('onEmptied')).toEqual(true)510 expect(validAttr('onEmptiedCapture')).toEqual(true)511 expect(validAttr('onEncrypted')).toEqual(true)512 expect(validAttr('onEncryptedCapture')).toEqual(true)513 expect(validAttr('onEnded')).toEqual(true)514 expect(validAttr('onEndedCapture')).toEqual(true)515 expect(validAttr('onError')).toEqual(true)516 expect(validAttr('onErrorCapture')).toEqual(true)517 expect(validAttr('onLoadedData')).toEqual(true)518 expect(validAttr('onLoadedDataCapture')).toEqual(true)519 expect(validAttr('onLoadedMetadata')).toEqual(true)520 expect(validAttr('onLoadedMetadataCapture')).toEqual(true)521 expect(validAttr('onLoadStart')).toEqual(true)522 expect(validAttr('onLoadStartCapture')).toEqual(true)523 expect(validAttr('onPause')).toEqual(true)524 expect(validAttr('onPauseCapture')).toEqual(true)525 expect(validAttr('onPlay')).toEqual(true)526 expect(validAttr('onPlayCapture')).toEqual(true)527 expect(validAttr('onPlaying')).toEqual(true)528 expect(validAttr('onPlayingCapture')).toEqual(true)529 expect(validAttr('onProgress')).toEqual(true)530 expect(validAttr('onProgressCapture')).toEqual(true)531 expect(validAttr('onRateChange')).toEqual(true)532 expect(validAttr('onRateChangeCapture')).toEqual(true)533 expect(validAttr('onSeeked')).toEqual(true)534 expect(validAttr('onSeekedCapture')).toEqual(true)535 expect(validAttr('onSeeking')).toEqual(true)536 expect(validAttr('onSeekingCapture')).toEqual(true)537 expect(validAttr('onStalled')).toEqual(true)538 expect(validAttr('onStalledCapture')).toEqual(true)539 expect(validAttr('onSuspend')).toEqual(true)540 expect(validAttr('onSuspendCapture')).toEqual(true)541 expect(validAttr('onTimeUpdate')).toEqual(true)542 expect(validAttr('onTimeUpdateCapture')).toEqual(true)543 expect(validAttr('onVolumeChange')).toEqual(true)544 expect(validAttr('onVolumeChangeCapture')).toEqual(true)545 expect(validAttr('onWaiting')).toEqual(true)546 expect(validAttr('onWaitingCapture')).toEqual(true)547 expect(validAttr('onLoad')).toEqual(true)548 expect(validAttr('onLoadCapture')).toEqual(true)549 expect(validAttr('onAnimationStart')).toEqual(true)550 expect(validAttr('onAnimationStartCapture')).toEqual(true)551 expect(validAttr('onAnimationEnd')).toEqual(true)552 expect(validAttr('onAnimationEndCapture')).toEqual(true)553 expect(validAttr('onAnimationIteration')).toEqual(true)554 expect(validAttr('onAnimationIterationCapture')).toEqual(true)555 expect(validAttr('onTransitionEnd')).toEqual(true)556 expect(validAttr('onTransitionEndCapture')).toEqual(true)557 expect(validAttr('onPointerDown')).toEqual(true)558 expect(validAttr('onPointerMove')).toEqual(true)559 expect(validAttr('onPointerUp')).toEqual(true)560 expect(validAttr('onPointerCancel')).toEqual(true)561 expect(validAttr('onGotPointerCapture')).toEqual(true)562 expect(validAttr('onLostPointerCapture')).toEqual(true)563 expect(validAttr('onPointerEnter')).toEqual(true)564 expect(validAttr('onPointerLeave')).toEqual(true)565 expect(validAttr('onPointerOver')).toEqual(true)566 expect(validAttr('onPointerOut')).toEqual(true)567 })568 it('should not allow custom props', () => {569 expect(validAttr('isPrimary')).toEqual(false)570 expect(validAttr('primary')).toEqual(false)571 });572 it('should handle x attributes', () => {573 expect(validAttr('x-error-message')).toEqual(true)574 })...

Full Screen

Full Screen

format-test.js

Source:format-test.js Github

copy

Full Screen

1var vows = require("vows"),2 load = require("../load"),3 assert = require("../assert");4var suite = vows.describe("d3.format");5suite.addBatch({6 "format": {7 topic: load("format/format").expression("d3.format"),8 "returns a string": function(format) {9 assert.isString(format("d")(0));10 },11 "can zero fill": function(format) {12 var f = format("08d");13 assert.strictEqual(f(0), "00000000");14 assert.strictEqual(f(42), "00000042");15 assert.strictEqual(f(42000000), "42000000");16 assert.strictEqual(f(420000000), "420000000");17 assert.strictEqual(f(-4), "-0000004");18 assert.strictEqual(f(-42), "-0000042");19 assert.strictEqual(f(-4200000), "-4200000");20 assert.strictEqual(f(-42000000), "-42000000");21 },22 "can space fill": function(format) {23 var f = format("8d");24 assert.strictEqual(f(0), " 0");25 assert.strictEqual(f(42), " 42");26 assert.strictEqual(f(42000000), "42000000");27 assert.strictEqual(f(420000000), "420000000");28 assert.strictEqual(f(-4), " -4");29 assert.strictEqual(f(-42), " -42");30 assert.strictEqual(f(-4200000), "-4200000");31 assert.strictEqual(f(-42000000), "-42000000");32 },33 "can output fixed-point notation": function(format) {34 assert.strictEqual(format(".1f")(0.49), "0.5");35 assert.strictEqual(format(".2f")(0.449), "0.45");36 assert.strictEqual(format(".3f")(0.4449), "0.445");37 assert.strictEqual(format(".5f")(0.444449), "0.44445");38 assert.strictEqual(format(".1f")(100), "100.0");39 assert.strictEqual(format(".2f")(100), "100.00");40 assert.strictEqual(format(".3f")(100), "100.000");41 assert.strictEqual(format(".5f")(100), "100.00000");42 },43 "can output general notation": function(format) {44 assert.strictEqual(format(".1g")(0.049), "0.05");45 assert.strictEqual(format(".1g")(0.49), "0.5");46 assert.strictEqual(format(".2g")(0.449), "0.45");47 assert.strictEqual(format(".3g")(0.4449), "0.445");48 assert.strictEqual(format(".5g")(0.444449), "0.44445");49 assert.strictEqual(format(".1g")(100), "1e+2");50 assert.strictEqual(format(".2g")(100), "1.0e+2");51 assert.strictEqual(format(".3g")(100), "100");52 assert.strictEqual(format(".5g")(100), "100.00");53 assert.strictEqual(format(".5g")(100.2), "100.20");54 assert.strictEqual(format(".2g")(0.002), "0.0020");55 },56 "can output exponent notation ": function(format) {57 var f = format("e");58 assert.strictEqual(f(0), "0e+0");59 assert.strictEqual(f(42), "4.2e+1");60 assert.strictEqual(f(42000000), "4.2e+7");61 assert.strictEqual(f(420000000), "4.2e+8");62 assert.strictEqual(f(-4), "-4e+0");63 assert.strictEqual(f(-42), "-4.2e+1");64 assert.strictEqual(f(-4200000), "-4.2e+6");65 assert.strictEqual(f(-42000000), "-4.2e+7");66 assert.strictEqual(format(".0e")(42), "4e+1")67 assert.strictEqual(format(".3e")(42), "4.200e+1")68 },69 "can output SI prefix notation": function(format) {70 var f = format("s");71 assert.strictEqual(f(0), "0");72 assert.strictEqual(f(1), "1");73 assert.strictEqual(f(10), "10");74 assert.strictEqual(f(100), "100");75 assert.strictEqual(f(999.5), "999.5");76 assert.strictEqual(f(999500), "999.5k");77 assert.strictEqual(f(1000), "1k");78 assert.strictEqual(f(1400), "1.4k");79 assert.strictEqual(f(1500.5), "1.5005k");80 assert.strictEqual(f(0.000001), "1µ");81 },82 "can output SI prefix notation with appropriate rounding": function(format) {83 var f = format(".3s");84 assert.strictEqual(f(0), "0.00");85 assert.strictEqual(f(1), "1.00");86 assert.strictEqual(f(10), "10.0");87 assert.strictEqual(f(100), "100");88 assert.strictEqual(f(999.5), "1.00k");89 assert.strictEqual(f(999500), "1.00M");90 assert.strictEqual(f(1000), "1.00k");91 assert.strictEqual(f(1500.5), "1.50k");92 assert.strictEqual(f(145500000), "146M");93 assert.strictEqual(f(145999999.999999347), "146M");94 assert.strictEqual(f(1e26), "100Y");95 assert.strictEqual(f(0.000001), "1.00µ");96 assert.strictEqual(f(0.009995), "10.0m");97 var f = format(".4s");98 assert.strictEqual(f(999.5), "999.5");99 assert.strictEqual(f(999500), "999.5k");100 assert.strictEqual(f(0.009995), "9.995m");101 },102 "can output SI prefix notation with appropriate rounding and currency symbol": function(format) {103 var f = format("$.3s");104 assert.strictEqual(f(0), "$0.00");105 assert.strictEqual(f(1), "$1.00");106 assert.strictEqual(f(10), "$10.0");107 assert.strictEqual(f(100), "$100");108 assert.strictEqual(f(999.5), "$1.00k");109 assert.strictEqual(f(999500), "$1.00M");110 assert.strictEqual(f(1000), "$1.00k");111 assert.strictEqual(f(1500.5), "$1.50k");112 assert.strictEqual(f(145500000), "$146M");113 assert.strictEqual(f(145999999.999999347), "$146M");114 assert.strictEqual(f(1e26), "$100Y");115 assert.strictEqual(f(0.000001), "$1.00µ");116 assert.strictEqual(f(0.009995), "$10.0m");117 var f = format("$.4s");118 assert.strictEqual(f(999.5), "$999.5");119 assert.strictEqual(f(999500), "$999.5k");120 assert.strictEqual(f(0.009995), "$9.995m");121 },122 "SI prefix notation precision is consistent for small and large numbers": function(format) {123 assert.deepEqual(124 [ 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e-0, 1e1, 1e2, 1e3, 1e4, 1e5].map(format("s")),125 [ '10µ', '100µ', '1m', '10m', '100m', '1', '10', '100', '1k', '10k', '100k']);126 assert.deepEqual(127 [ 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e-0, 1e1, 1e2, 1e3, 1e4, 1e5].map(format(".4s")),128 ['10.00µ', '100.0µ', '1.000m', '10.00m', '100.0m', '1.000', '10.00', '100.0', '1.000k', '10.00k', '100.0k']);129 },130 "can output a currency": function(format) {131 var f = format("$");132 assert.strictEqual(f(0), "$0");133 assert.strictEqual(f(0.042), "$0.042");134 assert.strictEqual(f(0.42), "$0.42");135 assert.strictEqual(f(4.2), "$4.2");136 assert.strictEqual(f(-0.042), "-$0.042");137 assert.strictEqual(f(-0.42), "-$0.42");138 assert.strictEqual(f(-4.2), "-$4.2");139 },140 "can output a currency with comma-grouping and sign": function(format) {141 var f = format("+$,.2f");142 assert.strictEqual(f(0), "+$0.00");143 assert.strictEqual(f(0.429), "+$0.43");144 assert.strictEqual(f(-0.429), "-$0.43");145 assert.strictEqual(f(-1), "-$1.00");146 assert.strictEqual(f(1e4), "+$10,000.00");147 },148 "can output a currency with si-prefix notation": function(format) {149 var f = format("$.2s");150 assert.strictEqual(f(0), "$0.0");151 assert.strictEqual(f(2.5e5), "$250k");152 assert.strictEqual(f(-2.5e8), "-$250M");153 assert.strictEqual(f(2.5e11), "$250G");154 },155 "can output a percentage": function(format) {156 var f = format("%");157 assert.strictEqual(f(0), "0%");158 assert.strictEqual(f(0.042), "4%");159 assert.strictEqual(f(0.42), "42%");160 assert.strictEqual(f(4.2), "420%");161 assert.strictEqual(f(-0.042), "-4%");162 assert.strictEqual(f(-0.42), "-42%");163 assert.strictEqual(f(-4.2), "-420%");164 },165 "can output a percentage with rounding and sign": function(format) {166 var f = format("+.2p");167 assert.strictEqual(f(0.00123), "+0.12%");168 assert.strictEqual(f(0.0123), "+1.2%");169 assert.strictEqual(f(0.123), "+12%");170 assert.strictEqual(f(1.23), "+120%");171 assert.strictEqual(f(-0.00123), "-0.12%");172 assert.strictEqual(f(-0.0123), "-1.2%");173 assert.strictEqual(f(-0.123), "-12%");174 assert.strictEqual(f(-1.23), "-120%");175 },176 "can round to significant digits": function(format) {177 assert.strictEqual(format(".2r")(0), "0.0");178 assert.strictEqual(format(".1r")(0.049), "0.05");179 assert.strictEqual(format(".1r")(-0.049), "-0.05");180 assert.strictEqual(format(".1r")(0.49), "0.5");181 assert.strictEqual(format(".1r")(-0.49), "-0.5");182 assert.strictEqual(format(".2r")(0.449), "0.45");183 assert.strictEqual(format(".3r")(0.4449), "0.445");184 assert.strictEqual(format(".3r")(1.00), "1.00");185 assert.strictEqual(format(".3r")(0.9995), "1.00");186 assert.strictEqual(format(".5r")(0.444449), "0.44445");187 assert.strictEqual(format("r")(123.45), "123.45");188 assert.strictEqual(format(".1r")(123.45), "100");189 assert.strictEqual(format(".2r")(123.45), "120");190 assert.strictEqual(format(".3r")(123.45), "123");191 assert.strictEqual(format(".4r")(123.45), "123.5");192 assert.strictEqual(format(".5r")(123.45), "123.45");193 assert.strictEqual(format(".6r")(123.45), "123.450");194 assert.strictEqual(format(".1r")(0.9), "0.9");195 assert.strictEqual(format(".1r")(0.09), "0.09");196 assert.strictEqual(format(".1r")(0.949), "0.9");197 assert.strictEqual(format(".1r")(0.0949), "0.09");198 assert.strictEqual(format(".10r")(0.9999999999), "0.9999999999");199 assert.strictEqual(format(".15r")(0.999999999999999), "0.999999999999999");200 },201 "can round very small numbers": function(format) {202 var f = format(".2r");203 assert.strictEqual(f(1e-22), "0.00000000000000000000");204 },205 "can group thousands": function(format) {206 var f = format(",d");207 assert.strictEqual(f(0), "0");208 assert.strictEqual(f(42), "42");209 assert.strictEqual(f(42000000), "42,000,000");210 assert.strictEqual(f(420000000), "420,000,000");211 assert.strictEqual(f(-4), "-4");212 assert.strictEqual(f(-42), "-42");213 assert.strictEqual(f(-4200000), "-4,200,000");214 assert.strictEqual(f(-42000000), "-42,000,000");215 assert.strictEqual(f(1e21), "1e+21");216 },217 "can group thousands and zero fill": function(format) {218 assert.strictEqual(format("01,d")(0), "0");219 assert.strictEqual(format("01,d")(0), "0");220 assert.strictEqual(format("02,d")(0), "00");221 assert.strictEqual(format("03,d")(0), "000");222 assert.strictEqual(format("04,d")(0), "0,000");223 assert.strictEqual(format("05,d")(0), "0,000");224 assert.strictEqual(format("06,d")(0), "00,000");225 assert.strictEqual(format("08,d")(0), "0,000,000");226 assert.strictEqual(format("013,d")(0), "0,000,000,000");227 assert.strictEqual(format("021,d")(0), "0,000,000,000,000,000");228 assert.strictEqual(format("013,d")(-42000000), "-0,042,000,000");229 assert.strictEqual(format("012,d")(1e21), "0,000,001e+21");230 assert.strictEqual(format("013,d")(1e21), "0,000,001e+21");231 assert.strictEqual(format("014,d")(1e21), "00,000,001e+21");232 assert.strictEqual(format("015,d")(1e21), "000,000,001e+21");233 },234 "can group thousands and zero fill with overflow": function(format) {235 assert.strictEqual(format("01,d")(1), "1");236 assert.strictEqual(format("01,d")(1), "1");237 assert.strictEqual(format("02,d")(12), "12");238 assert.strictEqual(format("03,d")(123), "123");239 assert.strictEqual(format("05,d")(12345), "12,345");240 assert.strictEqual(format("08,d")(12345678), "12,345,678");241 assert.strictEqual(format("013,d")(1234567890123), "1,234,567,890,123");242 },243 "can group thousands and space fill": function(format) {244 assert.strictEqual(format("1,d")(0), "0");245 assert.strictEqual(format("1,d")(0), "0");246 assert.strictEqual(format("2,d")(0), " 0");247 assert.strictEqual(format("3,d")(0), " 0");248 assert.strictEqual(format("5,d")(0), " 0");249 assert.strictEqual(format("8,d")(0), " 0");250 assert.strictEqual(format("13,d")(0), " 0");251 assert.strictEqual(format("21,d")(0), " 0");252 },253 "can group thousands and space fill with overflow": function(format) {254 assert.strictEqual(format("1,d")(1), "1");255 assert.strictEqual(format("1,d")(1), "1");256 assert.strictEqual(format("2,d")(12), "12");257 assert.strictEqual(format("3,d")(123), "123");258 assert.strictEqual(format("5,d")(12345), "12,345");259 assert.strictEqual(format("8,d")(12345678), "12,345,678");260 assert.strictEqual(format("13,d")(1234567890123), "1,234,567,890,123");261 },262 "can group thousands with general notation": function(format) {263 var f = format(",g");264 assert.strictEqual(f(0), "0");265 assert.strictEqual(f(42), "42");266 assert.strictEqual(f(42000000), "42,000,000");267 assert.strictEqual(f(420000000), "420,000,000");268 assert.strictEqual(f(-4), "-4");269 assert.strictEqual(f(-42), "-42");270 assert.strictEqual(f(-4200000), "-4,200,000");271 assert.strictEqual(f(-42000000), "-42,000,000");272 },273 "can group thousands, space fill, and round to significant digits": function(format) {274 assert.strictEqual(format("10,.1f")(123456.49), " 123,456.5");275 assert.strictEqual(format("10,.2f")(1234567.449), "1,234,567.45");276 assert.strictEqual(format("10,.3f")(12345678.4449), "12,345,678.445");277 assert.strictEqual(format("10,.5f")(123456789.444449), "123,456,789.44445");278 assert.strictEqual(format("10,.1f")(123456), " 123,456.0");279 assert.strictEqual(format("10,.2f")(1234567), "1,234,567.00");280 assert.strictEqual(format("10,.3f")(12345678), "12,345,678.000");281 assert.strictEqual(format("10,.5f")(123456789), "123,456,789.00000");282 },283 "can display integers in fixed-point notation": function(format) {284 assert.strictEqual(format("f")(42), "42");285 },286 "will not display non-integers in integer format": function(format) {287 assert.strictEqual(format("d")(4.2), "");288 },289 "unicode character": function(format) {290 assert.strictEqual(format("c")(9731), "☃");291 },292 "binary": function(format) {293 assert.strictEqual(format("b")(10), "1010");294 },295 "binary with prefix": function(format) {296 assert.strictEqual(format("#b")(10), "0b1010");297 },298 "octal": function(format) {299 assert.strictEqual(format("o")(10), "12");300 },301 "octal with prefix": function(format) {302 assert.strictEqual(format("#o")(10), "0o12");303 },304 "hexadecimal (lowercase)": function(format) {305 assert.strictEqual(format("x")(3735928559), "deadbeef");306 },307 "hexadecimal (lowercase) with prefix": function(format) {308 assert.strictEqual(format("#x")(3735928559), "0xdeadbeef");309 },310 "hexadecimal (uppercase)": function(format) {311 assert.strictEqual(format("X")(3735928559), "DEADBEEF");312 },313 "hexadecimal (uppercase) with prefix": function(format) {314 assert.strictEqual(format("#X")(3735928559), "0xDEADBEEF");315 },316 "fill respects prefix": function(format) {317 assert.strictEqual(format("#20x")(3735928559), " 0xdeadbeef");318 },319 "align left": function(format) {320 assert.strictEqual(format("<1,d")(0), "0");321 assert.strictEqual(format("<1,d")(0), "0");322 assert.strictEqual(format("<2,d")(0), "0 ");323 assert.strictEqual(format("<3,d")(0), "0 ");324 assert.strictEqual(format("<5,d")(0), "0 ");325 assert.strictEqual(format("<8,d")(0), "0 ");326 assert.strictEqual(format("<13,d")(0), "0 ");327 assert.strictEqual(format("<21,d")(0), "0 ");328 },329 "align right": function(format) {330 assert.strictEqual(format(">1,d")(0), "0");331 assert.strictEqual(format(">1,d")(0), "0");332 assert.strictEqual(format(">2,d")(0), " 0");333 assert.strictEqual(format(">3,d")(0), " 0");334 assert.strictEqual(format(">5,d")(0), " 0");335 assert.strictEqual(format(">8,d")(0), " 0");336 assert.strictEqual(format(">13,d")(0), " 0");337 assert.strictEqual(format(">21,d")(0), " 0");338 assert.strictEqual(format(">21,d")(1000), " 1,000");339 assert.strictEqual(format(">21,d")(1e21), " 1e+21");340 },341 "align center": function(format) {342 assert.strictEqual(format("^1,d")(0), "0");343 assert.strictEqual(format("^1,d")(0), "0");344 assert.strictEqual(format("^2,d")(0), " 0");345 assert.strictEqual(format("^3,d")(0), " 0 ");346 assert.strictEqual(format("^5,d")(0), " 0 ");347 assert.strictEqual(format("^8,d")(0), " 0 ");348 assert.strictEqual(format("^13,d")(0), " 0 ");349 assert.strictEqual(format("^21,d")(0), " 0 ");350 assert.strictEqual(format("^21,d")(1000), " 1,000 ");351 assert.strictEqual(format("^21,d")(1e21), " 1e+21 ");352 },353 "pad after sign": function(format) {354 assert.strictEqual(format("=+1,d")(0), "+0");355 assert.strictEqual(format("=+1,d")(0), "+0");356 assert.strictEqual(format("=+2,d")(0), "+0");357 assert.strictEqual(format("=+3,d")(0), "+ 0");358 assert.strictEqual(format("=+5,d")(0), "+ 0");359 assert.strictEqual(format("=+8,d")(0), "+ 0");360 assert.strictEqual(format("=+13,d")(0), "+ 0");361 assert.strictEqual(format("=+21,d")(0), "+ 0");362 assert.strictEqual(format("=+21,d")(1e21), "+ 1e+21");363 },364 "pad after sign with currency": function(format) {365 assert.strictEqual(format("=+$1,d")(0), "+$0");366 assert.strictEqual(format("=+$1,d")(0), "+$0");367 assert.strictEqual(format("=+$2,d")(0), "+$0");368 assert.strictEqual(format("=+$3,d")(0), "+$0");369 assert.strictEqual(format("=+$5,d")(0), "+$ 0");370 assert.strictEqual(format("=+$8,d")(0), "+$ 0");371 assert.strictEqual(format("=+$13,d")(0), "+$ 0");372 assert.strictEqual(format("=+$21,d")(0), "+$ 0");373 assert.strictEqual(format("=+$21,d")(1e21), "+$ 1e+21");374 },375 "a space can denote positive numbers": function(format) {376 assert.strictEqual(format(" 1,d")(-1), "-1");377 assert.strictEqual(format(" 1,d")(0), " 0");378 assert.strictEqual(format(" 2,d")(0), " 0");379 assert.strictEqual(format(" 3,d")(0), " 0");380 assert.strictEqual(format(" 5,d")(0), " 0");381 assert.strictEqual(format(" 8,d")(0), " 0");382 assert.strictEqual(format(" 13,d")(0), " 0");383 assert.strictEqual(format(" 21,d")(0), " 0");384 assert.strictEqual(format(" 21,d")(1e21), " 1e+21");385 },386 "explicitly only use a sign for negative numbers": function(format) {387 assert.strictEqual(format("-1,d")(-1), "-1");388 assert.strictEqual(format("-1,d")(0), "0");389 assert.strictEqual(format("-2,d")(0), " 0");390 assert.strictEqual(format("-3,d")(0), " 0");391 assert.strictEqual(format("-5,d")(0), " 0");392 assert.strictEqual(format("-8,d")(0), " 0");393 assert.strictEqual(format("-13,d")(0), " 0");394 assert.strictEqual(format("-21,d")(0), " 0");395 },396 "can format negative zero": function(format) {397 assert.strictEqual(format("1d")(-0), "-0");398 assert.strictEqual(format("1f")(-0), "-0");399 },400 "supports \"n\" as an alias for \",g\"": function(format) {401 var f = format("n");402 assert.strictEqual(f(0.0042), "0.0042");403 assert.strictEqual(f(0.42), "0.42");404 assert.strictEqual(f(0), "0");405 assert.strictEqual(f(42), "42");406 assert.strictEqual(f(42000000), "42,000,000");407 assert.strictEqual(f(420000000), "420,000,000");408 assert.strictEqual(f(-4), "-4");409 assert.strictEqual(f(-42), "-42");410 assert.strictEqual(f(-4200000), "-4,200,000");411 assert.strictEqual(f(-42000000), "-42,000,000");412 assert.strictEqual(f(1e21), "1e+21");413 },414 "\"n\" with zero padding": function(format) {415 assert.strictEqual(format("01n")(0), "0");416 assert.strictEqual(format("01n")(0), "0");417 assert.strictEqual(format("02n")(0), "00");418 assert.strictEqual(format("03n")(0), "000");419 assert.strictEqual(format("05n")(0), "0,000");420 assert.strictEqual(format("08n")(0), "0,000,000");421 assert.strictEqual(format("013n")(0), "0,000,000,000");422 assert.strictEqual(format("021n")(0), "0,000,000,000,000,000");423 assert.strictEqual(format("013n")(-42000000), "-0,042,000,000");424 },425 "unreasonable precision values are clamped to reasonable values": function(format) {426 assert.strictEqual(format(".30f")(0), "0.00000000000000000000");427 assert.strictEqual(format(".0g")(1), "1");428 assert.strictEqual(format(",.-1f")(12345), "12,345");429 assert.strictEqual(format("+,.-1%")(123.45), "+12,345%");430 }431 }432});...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful