修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
@@ -1,116 +1,35 @@
|
||||
import stdio
|
||||
import stdint
|
||||
import zc.config as config
|
||||
import zc.test as test
|
||||
import zc.logic_test as logic
|
||||
import zc.class_test as class_test
|
||||
from stdint import *
|
||||
import w32.win32console
|
||||
import config
|
||||
import hashlib
|
||||
import binascii
|
||||
import zlib.pyzlib as zp
|
||||
|
||||
import t, c
|
||||
import testcheck
|
||||
|
||||
|
||||
def main() -> stdint.INT:
|
||||
stdio.printf("=== Hello World! ===\n")
|
||||
stdio.printf("Cross-module macros:\n")
|
||||
stdio.printf(" POSMAX: %d\n", config.POSMAX)
|
||||
stdio.printf(" MATH_SCALE: %d\n", config.MATH_SCALE)
|
||||
stdio.printf(" THRESHOLD: %d\n", config.THRESHOLD)
|
||||
stdio.printf(" SHIFT_AMOUNT: %d\n", config.SHIFT_AMOUNT)
|
||||
stdio.printf(" MASK_VALUE: 0x%x\n", config.MASK_VALUE)
|
||||
stdio.printf("\n=== While Loop Test ===\n")
|
||||
test.AboutSizeTWhileTest(10)
|
||||
stdio.printf("\n=== Math Basic Test (20, 6) ===\n")
|
||||
test.MathBasicTest(20, 6)
|
||||
stdio.printf("\n=== Math Advanced Test (value=15) ===\n")
|
||||
test.MathAdvancedTest(15)
|
||||
stdio.printf("\n=== While with Elif-Else Test (-2 to 12) ===\n")
|
||||
test.WhileWithElifElseTest(-2, 12)
|
||||
stdio.printf("\n=== Nested While with Macros Test ===\n")
|
||||
test.NestedWhileWithMacrosTest(3, 4)
|
||||
stdio.printf("\n=== Complex Condition Test (1, 2, 3) ===\n")
|
||||
test.ComplexConditionTest(1, 2, 3)
|
||||
stdio.printf("\n=== Retry Loop Test (8) ===\n")
|
||||
test.RetryLoopTest(8)
|
||||
stdio.printf("\n=== Bitwise Operations Test (0b1101101) ===\n")
|
||||
test.BitwiseOperationsTest(109)
|
||||
stdio.printf("\n=== Compound Assignment Math Test (15, 4) ===\n")
|
||||
test.CompoundAssignmentMathTest(15, 4)
|
||||
stdio.printf("\n=== Power and Modulo Test (2, 8) ===\n")
|
||||
test.PowerAndModuloTest(2, 8)
|
||||
stdio.printf("\n=== Mixed Arithmetic Test (5, 3, 4) ===\n")
|
||||
test.MixedArithmeticTest(5, 3, 4)
|
||||
stdio.printf("\n=== Math with While Loop Test (start=1, count=5) ===\n")
|
||||
test.MathWithWhileLoopTest(1, 5)
|
||||
stdio.printf("\n=== Complex Nested Math Test (7, 3) ===\n")
|
||||
test.ComplexNestedMathTest(7, 3)
|
||||
stdio.printf("\n=== Conditional Math Chain Test (value=10) ===\n")
|
||||
test.ConditionalMathChainTest(10)
|
||||
stdio.printf("\n=== Bit Manipulation Math Test (0xABCD) ===\n")
|
||||
test.BitManipulationMathTest(0xABCD)
|
||||
stdio.printf("\n============== COMPLEX LOGIC TESTS ==============\n")
|
||||
stdio.printf("\n=== For Range Basic Test (stop=5) ===\n")
|
||||
logic.ForRangeBasicTest(5)
|
||||
stdio.printf("\n=== For Range With Start Stop Step (start=1, stop=10, step=2) ===\n")
|
||||
logic.ForRangeWithStartStop(1, 10, 2)
|
||||
stdio.printf("\n=== Nested For Range Test (rows=2, cols=3) ===\n")
|
||||
logic.NestedForRangeTest(2, 3)
|
||||
stdio.printf("\n=== For With If Break Test (size=8) ===\n")
|
||||
logic.ForWithIfBreakTest(8)
|
||||
stdio.printf("\n=== For With If Continue Test (n=10) ===\n")
|
||||
logic.ForWithIfContinueTest(10)
|
||||
stdio.printf("\n=== For With Elif Branch Test (value=10) ===\n")
|
||||
logic.ForWithElifBranchTest(10)
|
||||
stdio.printf("\n=== While With If Elif Else Test (iterations=7) ===\n")
|
||||
logic.WhileWithIfElifElseTest(7)
|
||||
stdio.printf("\n=== While With Nested If Test (limit=4) ===\n")
|
||||
logic.WhileWithNestedIfTest(4)
|
||||
stdio.printf("\n=== While With Match Case Test (value=2) ===\n")
|
||||
logic.WhileWithMatchCaseTest(2)
|
||||
stdio.printf("\n=== While With Match Case Test (value=99) ===\n")
|
||||
logic.WhileWithMatchCaseTest(99)
|
||||
stdio.printf("\n=== While With Match Case NoBreak Test (value=3) ===\n")
|
||||
logic.WhileWithMatchCaseNoBreakTest(3)
|
||||
stdio.printf("\n=== Complex For While Match Test (outer=3, inner=3) ===\n")
|
||||
logic.ComplexForWhileMatchTest(3, 3)
|
||||
stdio.printf("\n=== For With Case And NoBreak Test (n=5) ===\n")
|
||||
logic.ForWithCaseAndNoBreakTest(5)
|
||||
stdio.printf("\n=== While With Break Condition Test (limit=6) ===\n")
|
||||
logic.WhileWithBreakConditionTest(6)
|
||||
stdio.printf("\n=== Nested While With Multiple BreakPoints (depth=3, width=4) ===\n")
|
||||
logic.NestedWhileWithMultipleBreakPoints(3, 4)
|
||||
stdio.printf("\n=== For With Match Case In Loop Test (iterations=9) ===\n")
|
||||
logic.ForWithMatchCaseInLoopTest(9)
|
||||
stdio.printf("\n=== Complex Logic With Elif Chains (a=3, b=5, c=7) ===\n")
|
||||
logic.ComplexLogicWithElifChains(3, 5, 7)
|
||||
stdio.printf("\n=== For Range With Step And Condition (n=12, step=2) ===\n")
|
||||
logic.ForRangeWithStepAndCondition(12, 2)
|
||||
stdio.printf("\n=== Match Case With Guard Conditions (value=1) ===\n")
|
||||
logic.MatchCaseWithGuardConditions(1)
|
||||
stdio.printf("\n=== While With Multiple Match Cases (iterations=12) ===\n")
|
||||
logic.WhileWithMultipleMatchCases(12)
|
||||
stdio.printf("\n=== For While Mix With Break And Continue (n=5) ===\n")
|
||||
logic.ForWhileMixWithBreakAndContinue(5)
|
||||
stdio.printf("\n=== Complex Case Matching With Ranges (start=0, end=35) ===\n")
|
||||
logic.ComplexCaseMatchingWithRanges(0, 35)
|
||||
stdio.printf("\n=== While With Elif In Elif Chain (limit=7) ===\n")
|
||||
logic.WhileWithElifInElifChain(7)
|
||||
stdio.printf("\n=== For With Case NoBreak Nested (inner_limit=4) ===\n")
|
||||
logic.ForWithCaseNoBreakNested(4)
|
||||
stdio.printf("\n============== CLASS TESTS ==============\n")
|
||||
class_test.TestBasicDataClass()
|
||||
class_test.TestPoint3DClass()
|
||||
class_test.TestStudentClass()
|
||||
class_test.TestCounterClass()
|
||||
class_test.TestStackAllocation()
|
||||
class_test.TestHeapAllocation()
|
||||
class_test.TestHeapObjectWithInit()
|
||||
class_test.TestMultipleStackObjects()
|
||||
class_test.TestImplicitInitCall()
|
||||
class_test.TestClassWithBitFields()
|
||||
stdio.printf("\n============== ARRAY TESTS ==============\n")
|
||||
class_test.TestIntArray()
|
||||
class_test.TestFloatArray()
|
||||
class_test.TestCharArray()
|
||||
class_test.TestNestedArray()
|
||||
class_test.TestArrayWithStruct()
|
||||
class_test.TestArrayPointer()
|
||||
class_test.TestDynamicString()
|
||||
stdio.printf("\n============== All Tests Completed ==============\n")
|
||||
return 0
|
||||
def main() -> t.CInt | t.CExport:
|
||||
w32.win32console.SetConsoleCP(65001)
|
||||
w32.win32console.SetConsoleOutputCP(65001)
|
||||
|
||||
testcheck.begin("TestProject2: 综合库测试")
|
||||
|
||||
testcheck.section("zlib runtime version")
|
||||
print(zp.runtime_version())
|
||||
testcheck.ok("zlib runtime version printed")
|
||||
|
||||
testcheck.section("HASHLIB")
|
||||
md5_buf: t.CArray[t.CUInt8T, hashlib.MD5_DIGEST_LEN]
|
||||
mctx = hashlib.md5()
|
||||
mctx.update("hello")
|
||||
mctx.final(md5_buf)
|
||||
testcheck.ok("HASHLIB md5 completed")
|
||||
|
||||
testcheck.section("BINASCII")
|
||||
binascii.init_binascii()
|
||||
crc_val: t.CUnsignedInt = binascii.crc32("hello", 5, 0)
|
||||
testcheck.ok("BINASCII crc32 completed")
|
||||
|
||||
testcheck.info("END")
|
||||
return testcheck.end()
|
||||
|
||||
@@ -155,7 +155,7 @@ def TestClassWithBitFields():
|
||||
|
||||
def TestIntArray():
|
||||
stdio.printf("=== Test Int Array ===\n")
|
||||
arr: list[t.CInt, 5] = list[t.CInt, 5]()
|
||||
arr: t.CArray[t.CInt, 5] = t.CArray[t.CInt, 5]()
|
||||
i: t.CInt = 0
|
||||
while i < 5:
|
||||
arr[i] = i * 10
|
||||
@@ -168,7 +168,7 @@ def TestIntArray():
|
||||
|
||||
def TestFloatArray():
|
||||
stdio.printf("=== Test Float Array ===\n")
|
||||
farr: list[t.CFloat, 4] = list[t.CFloat, 4]()
|
||||
farr: t.CArray[t.CFloat, 4] = t.CArray[t.CFloat, 4]()
|
||||
farr[0] = 1.5
|
||||
farr[1] = 2.5
|
||||
farr[2] = 3.5
|
||||
@@ -181,7 +181,7 @@ def TestFloatArray():
|
||||
|
||||
def TestCharArray():
|
||||
stdio.printf("=== Test Char Array (String) ===\n")
|
||||
str_arr: list[t.CChar, 32] = list[t.CChar, 32]()
|
||||
str_arr: t.CArray[t.CChar, 32] = t.CArray[t.CChar, 32]()
|
||||
str_arr[0] = 'H'
|
||||
str_arr[1] = 'e'
|
||||
str_arr[2] = 'l'
|
||||
@@ -193,8 +193,8 @@ def TestCharArray():
|
||||
|
||||
def TestNestedArray():
|
||||
stdio.printf("=== Test Nested Array (Array of Arrays) ===\n")
|
||||
row0: list[t.CInt, 3] = list[t.CInt, 3]()
|
||||
row1: list[t.CInt, 3] = list[t.CInt, 3]()
|
||||
row0: t.CArray[t.CInt, 3] = t.CArray[t.CInt, 3]()
|
||||
row1: t.CArray[t.CInt, 3] = t.CArray[t.CInt, 3]()
|
||||
row0[0] = 0
|
||||
row0[1] = 1
|
||||
row0[2] = 2
|
||||
@@ -215,7 +215,7 @@ def TestNestedArray():
|
||||
|
||||
def TestArrayWithStruct():
|
||||
stdio.printf("=== Test Array with Struct ===\n")
|
||||
points: list[SimpleData, 3] = list[SimpleData, 3]()
|
||||
points: t.CArray[SimpleData, 3] = t.CArray[SimpleData, 3]()
|
||||
i: t.CInt = 0
|
||||
while i < 3:
|
||||
points[i].x = i * 10
|
||||
@@ -229,7 +229,7 @@ def TestArrayWithStruct():
|
||||
|
||||
def TestArrayPointer():
|
||||
stdio.printf("=== Test Array Pointer ===\n")
|
||||
data: list[t.CInt, 8] = list[t.CInt, 8]()
|
||||
data: t.CArray[t.CInt, 8] = t.CArray[t.CInt, 8]()
|
||||
data[0] = 100
|
||||
data[1] = 200
|
||||
data[2] = 300
|
||||
|
||||
Reference in New Issue
Block a user