103 lines
3.1 KiB
Plaintext
103 lines
3.1 KiB
Plaintext
type Row {
|
|
label: Text
|
|
count: Int
|
|
other: Int
|
|
}
|
|
|
|
type Nested {
|
|
row: Row
|
|
label: Text
|
|
}
|
|
|
|
change(state: Row, delta: Int) (answer: Row) {
|
|
answer = state
|
|
answer.count = state.count + delta
|
|
answer.other = state.other + answer.count
|
|
answer.label = state.label + "!"
|
|
}
|
|
|
|
keepOld(state: Row) (answer: Row) {
|
|
answer = state
|
|
answer.count = 99
|
|
answer.other = state.count
|
|
}
|
|
|
|
total(state: Row) (answer: Int) {
|
|
answer = state.count
|
|
}
|
|
|
|
keepWhole(state: Row) (answer: Row) {
|
|
answer = state
|
|
answer.count = 99
|
|
answer.other = total(state)
|
|
}
|
|
|
|
readWhole(state: Row) (answer: Row) {
|
|
answer = state
|
|
answer.count = total(state) + 1
|
|
}
|
|
|
|
changeSource(state: Row) (answer: Row) {
|
|
answer = state
|
|
state.count = 99
|
|
answer.other = state.count
|
|
}
|
|
|
|
changeNested(state: Nested) (answer: Nested) {
|
|
answer = state
|
|
answer.row.count = state.row.count + 1
|
|
answer.row.other = state.row.count
|
|
answer.label = state.label + "!"
|
|
}
|
|
|
|
faultEntry() (answer: Row) {
|
|
answer = change(Row { label = "x"
|
|
count = 9223372036854775807
|
|
other = 0 }, 1)
|
|
}
|
|
|
|
fieldValues() (answer: Bool) {
|
|
source = Nested { row = Row { label = "雪", count = 7, other = 9 }, label = "外" }
|
|
moved = Nested { label = source.label, row = source.row }
|
|
answer = moved.label == "外" and moved.row.label == "雪"
|
|
source = Nested { row = Row { label = "重叠", count = 3, other = 5 }, label = "未使用" }
|
|
overlap = Nested { row = source.row, label = source.row.label }
|
|
answer = answer and overlap.row.label == "重叠" and overlap.label == "重叠"
|
|
row = Row { label = "借用", count = 11, other = 13 }
|
|
borrowed = Row { label = row.label, count = total(row), other = row.other }
|
|
answer = answer and borrowed.label == "借用" and borrowed.count == 11 and borrowed.other == 13
|
|
row = Row { label = "保留", count = 17, other = 19 }
|
|
copied = Row { label = row.label, count = row.count, other = row.other }
|
|
row.label = "新值"
|
|
answer = answer and copied.label == "保留" and row.label == "新值"
|
|
}
|
|
|
|
verify() (answer: Bool) {
|
|
original = Row { label = "雪"
|
|
count = 7
|
|
other = 9 }
|
|
changed = change(original, 2)
|
|
answer = changed.label == "雪!" and changed.count == 9 and changed.other == 18
|
|
answer = answer and original.label == "雪" and original.count == 7 and original.other == 9
|
|
answer = answer and keepOld(original).other == 7 and keepWhole(original).other == 7
|
|
answer = answer and readWhole(original).count == 8 and changeSource(original).other == 99
|
|
temporary = keepOld(Row { label = "x"
|
|
count = 3
|
|
other = 0 })
|
|
answer = answer and temporary.count == 99 and temporary.other == 3
|
|
temporary = keepWhole(Row { label = "x"
|
|
count = 4
|
|
other = 0 })
|
|
answer = answer and temporary.other == 4
|
|
temporary = readWhole(Row { label = "x"
|
|
count = 5
|
|
other = 0 })
|
|
answer = answer and temporary.count == 6
|
|
nested = Nested { row = original
|
|
label = "outer" }
|
|
result = changeNested(nested)
|
|
answer = answer and result.row.count == 8 and result.row.other == 7 and result.label == "outer!"
|
|
answer = answer and nested.row.count == 7 and nested.row.other == 9 and nested.label == "outer"
|
|
answer = answer and fieldValues()
|
|
}
|