# test that the data capacity is correct data_capacity = { 1: { "L": {0: 152, 1: 41, 2: 25, 4: 17, 8: 10, }, "M": {0: 128, 1: 34, 2: 20, 4: 14, 8: 8, }, "Q": {0: 104, 1: 27, 2: 16, 4: 11, 8: 7, }, "H": {0: 72, 1: 17, 2: 10, 4: 7, 8: 4, }}, 2: { "L": {0: 272, 1: 77, 2: 47, 4: 32, 8: 20, }, "M": {0: 224, 1: 63, 2: 38, 4: 26, 8: 16, }, "Q": {0: 176, 1: 48, 2: 29, 4: 20, 8: 12, }, "H": {0: 128, 1: 34, 2: 20, 4: 14, 8: 8, }}, 3: { "L": {0: 440, 1: 127, 2: 77, 4: 53, 8: 32, }, "M": {0: 352, 1: 101, 2: 61, 4: 42, 8: 26, }, "Q": {0: 272, 1: 77, 2: 47, 4: 32, 8: 20, }, "H": {0: 208, 1: 58, 2: 35, 4: 24, 8: 15, }}, 4: { "L": {0: 640, 1: 187, 2: 114, 4: 78, 8: 48, }, "M": {0: 512, 1: 149, 2: 90, 4: 62, 8: 38, }, "Q": {0: 384, 1: 111, 2: 67, 4: 46, 8: 28, }, "H": {0: 288, 1: 82, 2: 50, 4: 34, 8: 21, }}, 5: { "L": {0: 864, 1: 255, 2: 154, 4: 106, 8: 65, }, "M": {0: 688, 1: 202, 2: 122, 4: 84, 8: 52, }, "Q": {0: 496, 1: 144, 2: 87, 4: 60, 8: 37, }, "H": {0: 368, 1: 106, 2: 64, 4: 44, 8: 27, }}, 6: { "L": {0: 1088, 1: 322, 2: 195, 4: 134, 8: 82, }, "M": {0: 864, 1: 255, 2: 154, 4: 106, 8: 65, }, "Q": {0: 608, 1: 178, 2: 108, 4: 74, 8: 45, }, "H": {0: 480, 1: 139, 2: 84, 4: 58, 8: 36, }}, 7: { "L": {0: 1248, 1: 370, 2: 224, 4: 154, 8: 95, }, "M": {0: 992, 1: 293, 2: 178, 4: 122, 8: 75, }, "Q": {0: 704, 1: 207, 2: 125, 4: 86, 8: 53, }, "H": {0: 528, 1: 154, 2: 93, 4: 64, 8: 39, }}, 8: { "L": {0: 1552, 1: 461, 2: 279, 4: 192, 8: 118, }, "M": {0: 1232, 1: 365, 2: 221, 4: 152, 8: 93, }, "Q": {0: 880, 1: 259, 2: 157, 4: 108, 8: 66, }, "H": {0: 688, 1: 202, 2: 122, 4: 84, 8: 52, }}, 9: { "L": {0: 1856, 1: 552, 2: 335, 4: 230, 8: 141, }, "M": {0: 1456, 1: 432, 2: 262, 4: 180, 8: 111, }, "Q": {0: 1056, 1: 312, 2: 189, 4: 130, 8: 80, }, "H": {0: 800, 1: 235, 2: 143, 4: 98, 8: 60, }}, 10: { "L": {0: 2192, 1: 652, 2: 395, 4: 271, 8: 167, }, "M": {0: 1728, 1: 513, 2: 311, 4: 213, 8: 131, }, "Q": {0: 1232, 1: 364, 2: 221, 4: 151, 8: 93, }, "H": {0: 976, 1: 288, 2: 174, 4: 119, 8: 74, }}, 11: { "L": {0: 2592, 1: 772, 2: 468, 4: 321, 8: 198, }, "M": {0: 2032, 1: 604, 2: 366, 4: 251, 8: 155, }, "Q": {0: 1440, 1: 427, 2: 259, 4: 177, 8: 109, }, "H": {0: 1120, 1: 331, 2: 200, 4: 137, 8: 85, }}, 12: { "L": {0: 2960, 1: 883, 2: 535, 4: 367, 8: 226, }, "M": {0: 2320, 1: 691, 2: 419, 4: 287, 8: 177, }, "Q": {0: 1648, 1: 489, 2: 296, 4: 203, 8: 125, }, "H": {0: 1264, 1: 374, 2: 227, 4: 155, 8: 96, }}, 13: { "L": {0: 3424, 1: 1022, 2: 619, 4: 425, 8: 262, }, "M": {0: 2672, 1: 796, 2: 483, 4: 331, 8: 204, }, "Q": {0: 1952, 1: 580, 2: 352, 4: 241, 8: 149, }, "H": {0: 1440, 1: 427, 2: 259, 4: 177, 8: 109, }}, 14: { "L": {0: 3688, 1: 1101, 2: 667, 4: 458, 8: 282, }, "M": {0: 2920, 1: 871, 2: 528, 4: 362, 8: 223, }, "Q": {0: 2088, 1: 621, 2: 376, 4: 258, 8: 159, }, "H": {0: 1576, 1: 468, 2: 283, 4: 194, 8: 120, }}, 15: { "L": {0: 4184, 1: 1250, 2: 758, 4: 520, 8: 320, }, "M": {0: 3320, 1: 991, 2: 600, 4: 412, 8: 254, }, "Q": {0: 2360, 1: 703, 2: 426, 4: 292, 8: 180, }, "H": {0: 1784, 1: 530, 2: 321, 4: 220, 8: 136, }}, 16: { "L": {0: 4712, 1: 1408, 2: 854, 4: 586, 8: 361, }, "M": {0: 3624, 1: 1082, 2: 656, 4: 450, 8: 277, }, "Q": {0: 2600, 1: 775, 2: 470, 4: 322, 8: 198, }, "H": {0: 2024, 1: 602, 2: 365, 4: 250, 8: 154, }}, 17: { "L": {0: 5176, 1: 1548, 2: 938, 4: 644, 8: 397, }, "M": {0: 4056, 1: 1212, 2: 734, 4: 504, 8: 310, }, "Q": {0: 2936, 1: 876, 2: 531, 4: 364, 8: 224, }, "H": {0: 2264, 1: 674, 2: 408, 4: 280, 8: 173, }}, 18: { "L": {0: 5768, 1: 1725, 2: 1046, 4: 718, 8: 442, }, "M": {0: 4504, 1: 1346, 2: 816, 4: 560, 8: 345, }, "Q": {0: 3176, 1: 948, 2: 574, 4: 394, 8: 243, }, "H": {0: 2504, 1: 746, 2: 452, 4: 310, 8: 191, }}, 19: { "L": {0: 6360, 1: 1903, 2: 1153, 4: 792, 8: 488, }, "M": {0: 5016, 1: 1500, 2: 909, 4: 624, 8: 384, }, "Q": {0: 3560, 1: 1063, 2: 644, 4: 442, 8: 272, }, "H": {0: 2728, 1: 813, 2: 493, 4: 338, 8: 208, }}, 20: { "L": {0: 6888, 1: 2061, 2: 1249, 4: 858, 8: 528, }, "M": {0: 5352, 1: 1600, 2: 970, 4: 666, 8: 410, }, "Q": {0: 3880, 1: 1159, 2: 702, 4: 482, 8: 297, }, "H": {0: 3080, 1: 919, 2: 557, 4: 382, 8: 235, }}, 21: { "L": {0: 7456, 1: 2232, 2: 1352, 4: 929, 8: 572, }, "M": {0: 5712, 1: 1708, 2: 1035, 4: 711, 8: 438, }, "Q": {0: 4096, 1: 1224, 2: 742, 4: 509, 8: 314, }, "H": {0: 3248, 1: 969, 2: 587, 4: 403, 8: 248, }}, 22: { "L": {0: 8048, 1: 2409, 2: 1460, 4: 1003, 8: 618, }, "M": {0: 6256, 1: 1872, 2: 1134, 4: 779, 8: 480, }, "Q": {0: 4544, 1: 1358, 2: 823, 4: 565, 8: 348, }, "H": {0: 3536, 1: 1056, 2: 640, 4: 439, 8: 270, }}, 23: { "L": {0: 8752, 1: 2620, 2: 1588, 4: 1091, 8: 672, }, "M": {0: 6880, 1: 2059, 2: 1248, 4: 857, 8: 528, }, "Q": {0: 4912, 1: 1468, 2: 890, 4: 611, 8: 376, }, "H": {0: 3712, 1: 1108, 2: 672, 4: 461, 8: 284, }}, 24: { "L": {0: 9392, 1: 2812, 2: 1704, 4: 1171, 8: 721, }, "M": {0: 7312, 1: 2188, 2: 1326, 4: 911, 8: 561, }, "Q": {0: 5312, 1: 1588, 2: 963, 4: 661, 8: 407, }, "H": {0: 4112, 1: 1228, 2: 744, 4: 511, 8: 315, }}, 25: { "L": {0: 10208, 1: 3057, 2: 1853, 4: 1273, 8: 784, }, "M": {0: 8000, 1: 2395, 2: 1451, 4: 997, 8: 614, }, "Q": {0: 5744, 1: 1718, 2: 1041, 4: 715, 8: 440, }, "H": {0: 4304, 1: 1286, 2: 779, 4: 535, 8: 330, }}, 26: { "L": {0: 10960, 1: 3283, 2: 1990, 4: 1367, 8: 842, }, "M": {0: 8496, 1: 2544, 2: 1542, 4: 1059, 8: 652, }, "Q": {0: 6032, 1: 1804, 2: 1094, 4: 751, 8: 462, }, "H": {0: 4768, 1: 1425, 2: 864, 4: 593, 8: 365, }}, 27: { "L": {0: 11744, 1: 3514, 2: 2132, 4: 1465, 8: 902, }, "M": {0: 9024, 1: 2701, 2: 1637, 4: 1125, 8: 692, }, "Q": {0: 6464, 1: 1933, 2: 1172, 4: 805, 8: 496, }, "H": {0: 5024, 1: 1501, 2: 910, 4: 625, 8: 385, }}, 28: { "L": {0: 12248, 1: 3669, 2: 2223, 4: 1528, 8: 940, }, "M": {0: 9544, 1: 2857, 2: 1732, 4: 1190, 8: 732, }, "Q": {0: 6968, 1: 2085, 2: 1263, 4: 868, 8: 534, }, "H": {0: 5288, 1: 1581, 2: 958, 4: 658, 8: 405, }}, 29: { "L": {0: 13048, 1: 3909, 2: 2369, 4: 1628, 8: 1002, }, "M": {0: 10136, 1: 3035, 2: 1839, 4: 1264, 8: 778, }, "Q": {0: 7288, 1: 2181, 2: 1322, 4: 908, 8: 559, }, "H": {0: 5608, 1: 1677, 2: 1016, 4: 698, 8: 430, }}, 30: { "L": {0: 13880, 1: 4158, 2: 2520, 4: 1732, 8: 1066, }, "M": {0: 10984, 1: 3289, 2: 1994, 4: 1370, 8: 843, }, "Q": {0: 7880, 1: 2358, 2: 1429, 4: 982, 8: 604, }, "H": {0: 5960, 1: 1782, 2: 1080, 4: 742, 8: 457, }}, 31: { "L": {0: 14744, 1: 4417, 2: 2677, 4: 1840, 8: 1132, }, "M": {0: 11640, 1: 3486, 2: 2113, 4: 1452, 8: 894, }, "Q": {0: 8264, 1: 2473, 2: 1499, 4: 1030, 8: 634, }, "H": {0: 6344, 1: 1897, 2: 1150, 4: 790, 8: 486, }}, 32: { "L": {0: 15640, 1: 4686, 2: 2840, 4: 1952, 8: 1201, }, "M": {0: 12328, 1: 3693, 2: 2238, 4: 1538, 8: 947, }, "Q": {0: 8920, 1: 2670, 2: 1618, 4: 1112, 8: 684, }, "H": {0: 6760, 1: 2022, 2: 1226, 4: 842, 8: 518, }}, 33: { "L": {0: 16568, 1: 4965, 2: 3009, 4: 2068, 8: 1273, }, "M": {0: 13048, 1: 3909, 2: 2369, 4: 1628, 8: 1002, }, "Q": {0: 9368, 1: 2805, 2: 1700, 4: 1168, 8: 719, }, "H": {0: 7208, 1: 2157, 2: 1307, 4: 898, 8: 553, }}, 34: { "L": {0: 17528, 1: 5253, 2: 3183, 4: 2188, 8: 1347, }, "M": {0: 13800, 1: 4134, 2: 2506, 4: 1722, 8: 1060, }, "Q": {0: 9848, 1: 2949, 2: 1787, 4: 1228, 8: 756, }, "H": {0: 7688, 1: 2301, 2: 1394, 4: 958, 8: 590, }}, 35: { "L": {0: 18448, 1: 5529, 2: 3351, 4: 2303, 8: 1417, }, "M": {0: 14496, 1: 4343, 2: 2632, 4: 1809, 8: 1113, }, "Q": {0: 10288, 1: 3081, 2: 1867, 4: 1283, 8: 790, }, "H": {0: 7888, 1: 2361, 2: 1431, 4: 983, 8: 605, }}, 36: { "L": {0: 19472, 1: 5836, 2: 3537, 4: 2431, 8: 1496, }, "M": {0: 15312, 1: 4588, 2: 2780, 4: 1911, 8: 1176, }, "Q": {0: 10832, 1: 3244, 2: 1966, 4: 1351, 8: 832, }, "H": {0: 8432, 1: 2524, 2: 1530, 4: 1051, 8: 647, }}, 37: { "L": {0: 20528, 1: 6153, 2: 3729, 4: 2563, 8: 1577, }, "M": {0: 15936, 1: 4775, 2: 2894, 4: 1989, 8: 1224, }, "Q": {0: 11408, 1: 3417, 2: 2071, 4: 1423, 8: 876, }, "H": {0: 8768, 1: 2625, 2: 1591, 4: 1093, 8: 673, }}, 38: { "L": {0: 21616, 1: 6479, 2: 3927, 4: 2699, 8: 1661, }, "M": {0: 16816, 1: 5039, 2: 3054, 4: 2099, 8: 1292, }, "Q": {0: 12016, 1: 3599, 2: 2181, 4: 1499, 8: 923, }, "H": {0: 9136, 1: 2735, 2: 1658, 4: 1139, 8: 701, }}, 39: { "L": {0: 22496, 1: 6743, 2: 4087, 4: 2809, 8: 1729, }, "M": {0: 17728, 1: 5313, 2: 3220, 4: 2213, 8: 1362, }, "Q": {0: 12656, 1: 3791, 2: 2298, 4: 1579, 8: 972, }, "H": {0: 9776, 1: 2927, 2: 1774, 4: 1219, 8: 750, }}, 40: { "L": {0: 23648, 1: 7089, 2: 4296, 4: 2953, 8: 1817, }, "M": {0: 18672, 1: 5596, 2: 3391, 4: 2331, 8: 1435, }, "Q": {0: 13328, 1: 3993, 2: 2420, 4: 1663, 8: 1024, }, "H": {0: 10208, 1: 3057, 2: 1852, 4: 1273, 8: 784, }} } rust_data_capacity = [ [ [152, 41, 25, 17, 10], [128, 34, 20, 14, 8], [104, 27, 16, 11, 7], [72, 17, 10, 7, 4], ], [ [272, 77, 47, 32, 20], [224, 63, 38, 26, 16], [176, 48, 29, 20, 12], [128, 34, 20, 14, 8], ], [ [440, 127, 77, 53, 32], [352, 101, 61, 42, 26], [272, 77, 47, 32, 20], [208, 58, 35, 24, 15], ], [ [640, 187, 114, 78, 48], [512, 149, 90, 62, 38], [384, 111, 67, 46, 28], [288, 82, 50, 34, 21], ], [ [864, 255, 154, 106, 65], [688, 202, 122, 84, 52], [496, 144, 87, 60, 37], [368, 106, 64, 44, 27], ], [ [1088, 322, 195, 134, 82], [864, 255, 154, 106, 65], [608, 178, 108, 74, 45], [480, 139, 84, 58, 36], ], [ [1248, 370, 224, 154, 95], [992, 293, 178, 122, 75], [704, 207, 125, 86, 53], [528, 154, 93, 64, 39], ], [ [1552, 461, 279, 192, 118], [1232, 365, 221, 152, 93], [880, 259, 157, 108, 66], [688, 202, 122, 84, 52], ], [ [1856, 552, 335, 230, 141], [1456, 432, 262, 180, 111], [1056, 312, 189, 130, 80], [800, 235, 143, 98, 60], ], [ [2192, 652, 395, 271, 167], [1728, 513, 311, 213, 131], [1232, 364, 221, 151, 93], [976, 288, 174, 119, 74], ], [ [2592, 772, 468, 321, 198], [2032, 604, 366, 251, 155], [1440, 427, 259, 177, 109], [1120, 331, 200, 137, 85], ], [ [2960, 883, 535, 367, 226], [2320, 691, 419, 287, 177], [1648, 489, 296, 203, 125], [1264, 374, 227, 155, 96], ], [ [3424, 1022, 619, 425, 262], [2672, 796, 483, 331, 204], [1952, 580, 352, 241, 149], [1440, 427, 259, 177, 109], ], [ [3688, 1101, 667, 458, 282], [2920, 871, 528, 362, 223], [2088, 621, 376, 258, 159], [1576, 468, 283, 194, 120], ], [ [4184, 1250, 758, 520, 320], [3320, 991, 600, 412, 254], [2360, 703, 426, 292, 180], [1784, 530, 321, 220, 136], ], [ [4712, 1408, 854, 586, 361], [3624, 1082, 656, 450, 277], [2600, 775, 470, 322, 198], [2024, 602, 365, 250, 154], ], [ [5176, 1548, 938, 644, 397], [4056, 1212, 734, 504, 310], [2936, 876, 531, 364, 224], [2264, 674, 408, 280, 173], ], [ [5768, 1725, 1046, 718, 442], [4504, 1346, 816, 560, 345], [3176, 948, 574, 394, 243], [2504, 746, 452, 310, 191], ], [ [6360, 1903, 1153, 792, 488], [5016, 1500, 909, 624, 384], [3560, 1063, 644, 442, 272], [2728, 813, 493, 338, 208], ], [ [6888, 2061, 1249, 858, 528], [5352, 1600, 970, 666, 410], [3880, 1159, 702, 482, 297], [3080, 919, 557, 382, 235], ], [ [7456, 2232, 1352, 929, 572], [5712, 1708, 1035, 711, 438], [4096, 1224, 742, 509, 314], [3248, 969, 587, 403, 248], ], [ [8048, 2409, 1460, 1003, 618], [6256, 1872, 1134, 779, 480], [4544, 1358, 823, 565, 348], [3536, 1056, 640, 439, 270], ], [ [8752, 2620, 1588, 1091, 672], [6880, 2059, 1248, 857, 528], [4912, 1468, 890, 611, 376], [3712, 1108, 672, 461, 284], ], [ [9392, 2812, 1704, 1171, 721], [7312, 2188, 1326, 911, 561], [5312, 1588, 963, 661, 407], [4112, 1228, 744, 511, 315], ], [ [10208, 3057, 1853, 1273, 784], [8000, 2395, 1451, 997, 614], [5744, 1718, 1041, 715, 440], [4304, 1286, 779, 535, 330], ], [ [10960, 3283, 1990, 1367, 842], [8496, 2544, 1542, 1059, 652], [6032, 1804, 1094, 751, 462], [4768, 1425, 864, 593, 365], ], [ [11744, 3514, 2132, 1465, 902], [9024, 2701, 1637, 1125, 692], [6464, 1933, 1172, 805, 496], [5024, 1501, 910, 625, 385], ], [ [12248, 3669, 2223, 1528, 940], [9544, 2857, 1732, 1190, 732], [6968, 2085, 1263, 868, 534], [5288, 1581, 958, 658, 405], ], [ [13048, 3909, 2369, 1628, 1002], [10136, 3035, 1839, 1264, 778], [7288, 2181, 1322, 908, 559], [5608, 1677, 1016, 698, 430], ], [ [13880, 4158, 2520, 1732, 1066], [10984, 3289, 1994, 1370, 843], [7880, 2358, 1429, 982, 604], [5960, 1782, 1080, 742, 457], ], [ [14744, 4417, 2677, 1840, 1132], [11640, 3486, 2113, 1452, 894], [8264, 2473, 1499, 1030, 634], [6344, 1897, 1150, 790, 486], ], [ [15640, 4686, 2840, 1952, 1201], [12328, 3693, 2238, 1538, 947], [8920, 2670, 1618, 1112, 684], [6760, 2022, 1226, 842, 518], ], [ [16568, 4965, 3009, 2068, 1273], [13048, 3909, 2369, 1628, 1002], [9368, 2805, 1700, 1168, 719], [7208, 2157, 1307, 898, 553], ], [ [17528, 5253, 3183, 2188, 1347], [13800, 4134, 2506, 1722, 1060], [9848, 2949, 1787, 1228, 756], [7688, 2301, 1394, 958, 590], ], [ [18448, 5529, 3351, 2303, 1417], [14496, 4343, 2632, 1809, 1113], [10288, 3081, 1867, 1283, 790], [7888, 2361, 1431, 983, 605], ], [ [19472, 5836, 3537, 2431, 1496], [15312, 4588, 2780, 1911, 1176], [10832, 3244, 1966, 1351, 832], [8432, 2524, 1530, 1051, 647], ], [ [20528, 6153, 3729, 2563, 1577], [15936, 4775, 2894, 1989, 1224], [11408, 3417, 2071, 1423, 876], [8768, 2625, 1591, 1093, 673], ], [ [21616, 6479, 3927, 2699, 1661], [16816, 5039, 3054, 2099, 1292], [12016, 3599, 2181, 1499, 923], [9136, 2735, 1658, 1139, 701], ], [ [22496, 6743, 4087, 2809, 1729], [17728, 5313, 3220, 2213, 1362], [12656, 3791, 2298, 1579, 972], [9776, 2927, 1774, 1219, 750], ], [ [23648, 7089, 4296, 2953, 1817], [18672, 5596, 3391, 2331, 1435], [13328, 3993, 2420, 1663, 1024], [10208, 3057, 1852, 1273, 784], ], ]; error_dict = { 0: "L", 1: "M", 2: "Q", 3: "H", } mode_dict = { 0: 0, 1: 1, 2: 2, 3: 4, 4: 8, } for vi, version in enumerate(rust_data_capacity): for ei, error_correction in enumerate(version): for mi, mode in enumerate(error_correction): assert mode == rust_data_capacity[vi][ei][mi] r = rust_data_capacity[vi][ei][mi] pvi = vi + 1 pei = error_dict[ei] pmi = mode_dict[mi] assert r == data_capacity[pvi][pei][pmi] print("All tests passed!")