⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 heapstest.java

📁 只是一个简单模拟操作系统
💻 JAVA
字号:
/*
 * HeapsTest.java
 * JUnit based test
 *
 * Created on 2006年3月18日, 上午10:23
 */

package os.process;

import junit.framework.*;

/**
 *
 * @author Vernkin
 */
public class HeapsTest extends TestCase {
    
    Heaps io;
    Heaps other;
    
    
    MyProcess p11;
    MyProcess p21;
    MyProcess p31;
    
    MyProcess p12;
    MyProcess p22;
    MyProcess p32;
    
    
    public HeapsTest(String testName) {
        super(testName);
    }

    protected void setUp() throws Exception {
        io = new Heaps("IO", 10, true);
        other = new Heaps("Other", 10, false);
        p11 = new MyProcess("p11");
        p21 = new MyProcess("p21");
        p31 = new MyProcess("p31", 5);
        
        p12 = new MyProcess("p12");
        p22 = new MyProcess("p22");
        p32 = new MyProcess("p32", 5);
    }

    public static Test suite() {
        TestSuite suite = new TestSuite(HeapsTest.class);
        
        return suite;
    }
    
    public static void main(String[] args){
        junit.textui.TestRunner.run(suite());
    }

    /**
     * add 方法的测试(属于类 os.process.Heaps)。
     */
    public void testAdd() {
        System.out.println("testAdd");
        
        // TODO 通过替换失败的缺省调用在下面添加测试代码。
        this.assertEquals(null,io.getFirstProcess());
        io.add(p11);
        this.assertEquals(0,io.getSize());
        io.add(p21);
        this.assertEquals(1,io.getSize());
        this.assertTrue(io.getFirstProcess() == p11);
        io.add(p31);
        this.assertTrue(io.getFirstProcess() == p11);
        this.assertEquals(2,io.getSize());
        
        other.add(p12);
        other.add(p22);
        this.assertTrue(other.getFirstProcess() == p12);
        other.add(p32);
        this.assertTrue(other.getFirstProcess() == p32);
    }

    /**
     * findMax 方法的测试(属于类 os.process.Heaps)。
     */
    public void testFindMax() {
        System.out.println("testFindMax");
        
        p21.setSystemID();
        p11.setSystemID();
        p31.setSystemID();
        io.add(p11);
        io.add(p21);
        io.add(p31);
        assertTrue(io.findMax() == p11);
        assertTrue(io.findMax() == p31);
        assertTrue(io.getFirstProcess() == p21);
        
        p22.setSystemID();
        p12.setSystemID();
        p32.setSystemID();
        
        
        other.add(p22);
        other.add(p32);
        other.add(p12);
        
        assertTrue(other.findMax()== p32);
        assertTrue(other.findMax()== p22);
        assertTrue(other.findMax()== p12);
        
    }

    /**
     * isEmpty 方法的测试(属于类 os.process.Heaps)。
     */
    public void testIsEmpty() {
        System.out.println("testIsEmpty");
        this.assertTrue(io.isEmpty());
        io.add(p11);
        this.assertEquals(0,io.getSize());
        this.assertTrue(!io.isEmpty());
        
        p22.setSystemID();
        p21.setSystemID();
        this.assertTrue(other.isEmpty());
        
        other.add(p21);
        other.add(p22);
        this.assertEquals(2,other.getSize());
        this.assertTrue(other.getFirstProcess() == p22);
        
        
        other.makeEmpty();
        this.assertTrue(other.isEmpty());
        

    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -