期中测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了期中测试相关的知识,希望对你有一定的参考价值。

ScheduleTest:

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.junit.*;

public class ScheduleTest {
    Schedule s;
    Work a = new Work("a",1,3);
    Work b = new Work("b",2,2);
    Work c = new Work("c",3,2);
    Work d = new Work("d",3,1);
    List<Work> l,l2;
    @Before
    public void setup()
    {
        s = new Schedule();
        l = new ArrayList<Work>();
        l.add(a);
        l.add(b);
        l.add(c);
        l2 = new ArrayList<Work>();
        l2.add(c);
        l2.add(b);
        l2.add(d);
    }
    @Test
    public void testFCFS() 
    {
        List<Double> ll = new ArrayList<Double>();
        ll.add(4.0);ll.add(1.8333333333333333);
        List<Double> ld = s.FCFS(l);
        Iterator<Double> j = ll.iterator();
        for(Iterator<Double> i = ld.iterator();i.hasNext(); ){
            assertEquals(j.next(),i.next());
            }
    }

    @Test
    public void testSJF() {
        List<Double> ll = new ArrayList<Double>();
        ll.add(2.6666666666666665);ll.add(1.6666666666666667);
        List<Double> ld = s.SJF(l2);
        Iterator<Double> j = ll.iterator();
        for(Iterator<Double> i = ld.iterator();i.hasNext(); ){
            assertEquals(j.next(),i.next());
            }
    }
    @Test
    public void testGetPriority()
    {
        assertEquals(0,a.getPriority());
    }

}

SortingTest:

import static org.junit.Assert.*;

import org.junit.*;


public class SortingTest {
    
    Sorting s;
    
    @Before
    public void setup()
    {
        s = new Sorting();
    }
    
    @Test
    public void testInsertionSort() 
    {
        int [] an = {5,2,3,4,1};
        assertEquals(false,s.isSorted(an));
        s.insertionSort(an);
        assertEquals("whetherInsertSorted",true,s.isSorted(an));
    }
    
    @Test
    public void testIsSorted()
    {
        int [] an = {1,2,3,4};
        int [] bn = {1,4,3,2};
        assertEquals("whetherSorted",true,s.isSorted(an));
        assertEquals("whetherSorted",false,s.isSorted(bn));
    }
        
    @Test
    public void testQuicksort()
    {
        int [] an = {9,8,7,6,5,4,3,2,1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1};
        assertEquals(false,s.isSorted(an));
        s.quicksort(an);
        assertEquals("whetherQuickSorted",true,s.isSorted(an));
    }
    
    @Test
    public void testSwapReferences()
    {
        String [] an = {"1","2"};
        String [] bn = {"2","1"};
        s.swapReferences(an, 0, 1);
        assertEquals("whetherErrorSwap",bn,an);
        
    }
        
}

TriangleTest:

import static org.junit.Assert.*;

import org.junit.*;

public class TriangleTest {

    Triangle a;
    Triangle b;
    Triangle c;
    Triangle d;
    Triangle e;
    @Before
    public void setup()
    {
        a = new Triangle(-1,1,2);
        b = new Triangle(1,2,3);
        c = new Triangle(2,2,2);
        d = new Triangle(2,2,3);
        e = new Triangle(2,3,4);
    }
    @Test
    public void testIsTriangle() 
    {
        assertEquals(false,a.isTriangle(a));
        assertEquals(false,b.isTriangle(b));
        assertEquals(true,c.isTriangle(c));
    }

    @Test
    public void testGetType() {
        assertEquals("Illegal",b.getType(b));
        assertEquals("Regular",c.getType(c));
        assertEquals("Isosceles",d.getType(d));
        assertEquals("Scalene",e.getType(e));
    }
    @Test
    public void testGetBorders()
    {
        long [] an = {-1,1,2};
        long [] bn = a.getBorders();
        assertEquals(an[0],bn[0]);
        assertEquals(an[1],bn[1]);
        assertEquals(an[2],bn[2]);
    }

}

 

以上是关于期中测试的主要内容,如果未能解决你的问题,请参考以下文章

期中测试题1

期中测试题3

Python数据分析期中测试--百货商场案例

期中测试( 制作一个秒表计时器 )

2021年信号与系统处理期中考试与课堂交互分数

2019高一期中考试 std代码