其他分享
首页 > 其他分享> > OO第三

OO第三

作者:互联网

OO第三单元总结

一、测试数据准备

在本单元的作业中,采用了随机构造数据+对拍的方式进行测试

随机数据的生成

  1. 针对每次作业中可能会出错的一些方法,在充分理解其JML规格的基础之上对每个方法分别构造数据生成器并进行覆盖
  2. 对方法单独测试完毕之后,对一些方法进行组合进行综合测试,进一步提高覆盖率

边界数据的生成

在边界数据的生成中,JML规格限定的边界起到了重要作用,主要有以下几类边界数据

例如:针对RedMessage相关请求的数据生成器

import random
from tokenize import group
name = ["cry", "mxy", "jjw", "wzm", "gzb", "wgr"]
agepool = [0,198,45,9,20,100,140,88,37]
pnum = 800
gnum = 4
ap = "ap"
ar = "ar"
ag = "ag"
atg = "atg"
am = "am"
sim = "sim"
arem = "arem"
sm = "sm"
qm = "qm"
relation = set()
g = dict()


with open("./HW11test/stdin.txt", "w") as f:
    # add person
    for i in range(pnum):
        s = ap + " " + str(i) + " " + random.sample(name, 1)[0] + " " + str(random.randint(0,200)) + "\n"
        f.write(s)

    # add group
    for i in range(gnum):
        s = ag + " " + str(i) + "\n"
        f.write(s)
    
    # add to group
    for i in range(pnum):
        gi = random.randint(0, gnum - 1)
        s = atg + " " + str(i) + " " + str(gi) + "\n"
        g[i] = str(gi)
        f.write(s)
    
    
    # add relation
    for i in range(2*pnum):
        a = str(random.randint(0, pnum - 1))
        b = str(random.randint(0, pnum - 1))
        while((a, b) in relation or (b, a) in relation):
            a = str(random.randint(0, pnum - 1))
            b = str(random.randint(0, pnum - 1))
        relation.add((a, b))
        s = ar + " " + a + " " + b +  " " + str(random.randint(0,1000)) + "\n"
        f.write(s)

    # add RedMessage
    for i in range(200):
        t = random.randint(0, 1)
        if t == 0:
            p = random.sample(relation, 1)
            s = arem + " " + str(i) +  " " + str(random.randint(0,200)) + " " + "0" + " " + p[0][0] + " " + p[0][1] + "\n"
        else:
            p = random.randint(0, pnum - 1)
            gg = g[p]
            s = arem + " " + str(i) +  " " + str(random.randint(0,200)) + " " + "1" + " " + str(p) + " " + gg + "\n"
        f.write(s)
        
    # send message
    for i in range(200):
        s = sm + " " + str(i) + "\n"
        f.write(s)

    # query money
    for i in range(pnum):
        s = qm + " " + str(i) + "\n"
        f.write(s)

二、架构设计及模型维护

架构设计

容器的选择

图模型构建

图维护策略

三、性能问题和修复情况

性能问题

修复情况

四、Network拓展

假设出现了几种不同的Person

如此Network可以支持市场营销,并能查询某种商品的销售额和销售路径等 请讨论如何对Network扩展,给出相关接口方法,并选择3个核心业务功能的接口方法撰写JML规格

Advertiser、Producer、Customer都可以继承自Person类,实现的思路为生产者生产产品,广告商向外发送Message,消费者和生产者以广告商为媒介购买和生产产品

选择实现的接口规格如下

addAdvertisementMessage()

  /*@ public normal_behavior
      @ requires !containsMessage(message.getId());
      @ assignable messages;
      @ ensures messages.length == \old(messagess.length) + 1;
      @ ensures (\forall int i; 0 <= i && i < \old(messages.length);
      @         (\exists int j; 0 <= j && j < messages.length; messages[j].equals(\old(messages[i]))));
      @ ensures (\exists int i; 0 <= i && i < messages.length; messages[i].equals(message));
      @ also
      @ public exceptional_behavior
      @ signals (EqualMessageIdException e) containsMessage(message.getId());
      @ also
      @ public exceptional_behavior
      @ signals (AdvertiserNotFoundException e) 
      @ !(\exists int i; 0 <= i && i < messages.length; messages[i].equals(message)) 
      @ && !(messages[i].getPerson1() instanceof Advertiser);
*/
    public void addAdvertisementMessage(Message message) throws EqualMessageIdException, AdvertiserNotFoundException;

sendAdvertisementMessage()

/*@ public normal_behavior
      @ requires containsMessage(id) && getMessage(id) instanceof AdvertisementMessage;
      @ assignable messages;
      @ ensures (\forall int i; 0 <= i && i < people.length && 
      @ getMessage(id).getPerson1().isLinked(people[i]) 
      @ ensures (\forall int i; 0 <= i && i < people.length && 
      @!getMessage(id).getPerson1().isLinked(people[i]);
      @           people[i].getMessages().equals(\old(people[i].getMessages()));
      @ ensures !containsMessage(id) && messages.length == \old(messages.length) - 1 &&
      @         (\forall int i; 0 <= i && i < \old(messages.length) && \old(messages[i].getId()) != id;
      @         (\exists int j; 0 <= j && j < messages.length; messages[j].equals(\old(messages[i]))));
      @ also
      @ public exceptional_behavior
      @ signals (MessageIdNotFoundException e) !containsMessage(id);
      @*/
    public void sendAdvertisementMessage(int id) throws MessageIdNotFoundException;

createProduct()

/*@ public normal_behavior
      @ requires contains(peid) && (getPerson(peid) instanceof Producer);
      @ ensures getProducer(peid).getProductNumById(ptid) ==
      @           \old(getProducer(peid).getProductNumById(ptid)) + 1;
      @ also
      @ public exceptional_behavior
      @ signals (PersonIdNotFoundException e) !contains(peid);
      @*/
   	public void createProduct(int peid, int ptid) throws PersonIdNotFoundException;

五、心得体会

标签:OO,pnum,JML,randint,random,第三,write,str
来源: https://www.cnblogs.com/Tsundoku13/p/16341159.html