下面是我最近为手机短信完成的一个马马虎虎的合金规格。这只是基本的发短信要求,因为这是一种做法,我没有严格的要求要坚持。但是,我有一些尴尬的问题,例如为什么我不能获得超过 1 对 Name-Mobile 对?为什么 2 个 MessageSets 坚持指向一个 Name?除了问题之外,事实和谓词非常直截了当。请随意批评,因为我需要反馈来学习合金本身。
我在做以下事情时的想法;
一个 Message Box 有 0 个或多个 MessageSet。一套只属于一个人,没有一套是免费的。每组有 1 个或多个消息,由消息行、开始和结束键和行以及光标位置组成。多条消息可以属于同一个人,但一条消息不能同时属于 2 个人。每行有 1 个或多个键,并有它们的开始键和结束键。此外,一行可能有也可能没有新行。每个键可能有也可能没有下一个键。通过触摸板按下按键。每个名字都有一个手机号码,并记录在 ContactList 中。没有两个名字可以有相同的手机,但一个人可以有多个电话号码。
谢谢。
sig Lines{
formedOfKeys:some Keys,
lineStartKey:one Keys,
lineEndKey:one Keys,
nextLine: lone Lines,
}
one sig TouchPad{ pressed: set Keys }
sig Keys{ nextKey: one Keys, }
one sig MessageBox{}
sig MessageSet{
isIn:one MessageBox,
isSetOf: one Name
}
sig Messages{
belongsToSet: one MessageSet,
firstLine: one Lines,
lastLine:one Lines,
lastKey:one Keys,
firstKey: one Keys,
curserLoc: one Keys,
formedOfLines: set Lines,
sentFrom : one Name
}
sig Name,Mobile {}
one sig ContactList {
contact: Name,
mobile: contact -> one Mobile
}
fact No2NamesBelongingToMessageSetsSame{
// all ms1,ms2:MessageSet| ms2 = ms1 implies ms1.isSetOf != ms2.isSetOf
}
//make it more than 2
fact NameAndMobileNumbersMatchedAndEqual{
// #Name>2 and #Mobile>2
#Name=#Mobile
}
fact MessageSetBelongsToName{
all ms:MessageSet, m:Messages |ms.isSetOf=m.sentFrom
}
fact AllNamesInContactList{
all c:ContactList| #c.contact =#Name
}
fact NoLastMessageLineWithNextLine{
no l:Lines | l.nextLine not in (Messages.lastLine +Messages.firstLine)
}
fact NoNextKeyisSelf{
all k: Keys| k !in k.nextKey
}
fact NoNextLineisSelf{
all l: Lines | l !in l.nextLine
}
fact No2WayConnectionsBetweenLines{
all disj l1, l2: Lines | l2 in l1.nextLine implies l1 !in l2.nextLine
}
fact No2WayConnectionsBetweenKeys{
all disj k1, k2: Keys| k2 in k1.nextKey implies k1 !in k2.nextKey
}
fact MessageHasMoreThan1LineHasNextLine{
all m:Messages|#m.formedOfLines>1 implies #m.formedOfLines.nextLine>0
}
fact LineStartInMessageLines{ all l:Lines| l.lineStartKey in l.formedOfKeys }
fact LineEndInMessageLines{ all l:Lines| l.lineEndKey in l.formedOfKeys }
fact CurserLocInMessageKeys{ all m:Messages| m.curserLoc in m.formedOfLines.formedOfKeys }
fact FirstKeyInMessageKeys{ all m:Messages| m.firstKey in m.formedOfLines.formedOfKeys }
fact firstLineInMessageLines{ all m:Messages| m.firstLine in m.formedOfLines }
fact MessageNextLineInMessageLines{ all m:Messages| m.formedOfLines.nextLine in m.formedOfLines }
fact MessageFirstKeyisInLineStartKeySet{ all m:Messages , l:Lines | m.firstKey in l.lineStartKey }
fact MessageLastKeyisInLineEndKeySet{ all m:Messages , l:Lines | l in m.lastLine && l.lineEndKey in m.lastLine.lineEndKey }
fact allKeysArePressed { all k:Keys | k in TouchPad.pressed }
fact NoMessageSetsWithoutMessages{ no ms:MessageSet| ms not in Messages.belongsToSet }
fact NoMessageSetWithoutBox{ no mb:MessageBox| mb not in MessageSet.isIn }
pred nonReturnKeyPress[k: Keys, l,l':Lines, t:TouchPad]{
//key pressed in message, cursor and line info (new state =original state+1letter)
l'.formedOfKeys= l.formedOfKeys++(t.pressed)
}
pred deleteKeyPressed[k: Keys, l,l':Lines, t:TouchPad]{
//key deleted from line. cursor and line info (new state =original state-1key)
l'.formedOfKeys = l.formedOfKeys - (t.pressed)
}
pred returnKeyPressed[k: Keys, l,l':Lines, t:TouchPad]{
//TODO return key pressed. cursor loc is new line's cursor loc
l'.formedOfKeys= l.nextLine.formedOfKeys
}
assert keyPressWorks {
//TODO check if key press works properly
}
pred pressThenDeleteSame {
all l1,l2,l3: Lines, t:TouchPad, k: Keys|
nonReturnKeyPress [k,l1,l2,t] && deleteKeyPressed [k,l2,l3,t]
=> l1.formedOfKeys = l3.formedOfKeys
}
pred ReceiveThenSendSame {
all ms1,ms2,ms3, m: Messages|
receive [m,ms1,ms2] && send [m,ms2,ms3]
=> ms1 = ms3
}
pred findCursorLoc [l:Lines, k:lone Keys]{
//TODO I have a line and a key...How can i check where i am
}
pred send[m, mS,mS':Messages]{
//final message set is one less than previous
mS'= mS - (m)
}
pred receive[m, mS,mS':Messages]{
//final message set is one more than previous
mS'= mS++ (m)
}
pred AddContact [cl, cl': ContactList, n: Name, m: Mobile] {
cl'.mobile = cl.mobile ++ (n->m)
}
pred RemoveContact [cl, cl': ContactList, n: Name] {
cl'.mobile = cl.mobile - (n->Mobile)
}
pred FindContact [cl: ContactList, n: Name, m: Mobile] {
m = cl.mobile[n]
}
assert AddingContact {
all cl, cl': ContactList, n: Name, m,m': Mobile |
AddContact [cl,cl',n,m] && FindContact [cl',n,m'] => m = m'
}
assert AddingThenDeleteSame {
all cl1,cl2,cl3: ContactList, n: Name, m: Mobile|
AddContact [cl1,cl2,n,m] && RemoveContact [cl2,cl3,n]=> cl1.mobile = cl3.mobile
}
assert pressThenDeleteSame {
all l1,l2,l3: Lines, t:TouchPad, k: Keys|
nonReturnKeyPress [k,l1,l2,t] && deleteKeyPressed [k,l2,l3,t]=> l1.formedOfKeys = l3.formedOfKeys
}
assert ReceiveThenSendSame {
all ms1,ms2,ms3 , m: Messages|
receive [m,ms1,ms2] && send [m,ms2,ms3]=> ms1 = ms3
}
//check AddingContact expect 0
//check AddingThenDeleteSame expect 1
//check pressThenDeleteSame expect 0
//check ReceiveThenSendSame expect 0
pred show{ }
run show
//for exactly 3 Name,3 Mobile, 4 MessageSet,6 Messages, 5 Lines, 6 Keys
//for exactly 4 MessageSet,14 Messages, 20 Lines, 40 Keys