Đang chuẩn bị liên kết để tải về tài liệu:
The art of software testing second edition phần 10

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Nó kiểm tra xem đầu vào là một nguyên tố hợp lệ và làm thế nào ứng dụng hoạt động với một giá trị đầu vào hợp lệ. Bạn có thể sử dụng bất kỳ chính hợp lệ trong thử nghiệm này. Phụ lục B cung cấp một danh sách các số nguyên tố dưới 1.000 có thể được sử dụng. | 214 Appendix A public static void main String args Initialize class object to work with check4Prime check new check4Prime try Check arguments and assign value to input variable check.checkArgs args Check for Exception and display help catch Exception e System.out.println Usage check4Prime x System.out.println -- where 0 x 1000 System.exit l Check if input is a prime number if check.primeCheck input System.out.println Yippeee. input is a prime number else System.out.println Bummer. input is NOT a prime number End main Calculates prime numbers and compares it to the input public boolean primeCheck int num double sqroot Math.sqrt max Find square root of n Initialize array to hold prime numbers boolean primeBucket new boolean max 1 Initialize all elements to true then set non-primes to false for int i 2 i max i primeBucket i true Appendix A 215 Do all multiples of 2 first int j 2 for int i j j i max i i j primeBucket i false 1 for j 3 j sqroot j j 2 if primeBucket j true for int i j j i max i i j primeBucket i false 1 1 1 Check input against prime array if primeBucket num true return true 1else return false 1 end primeCheck start with 2j as 2 is prime set all multiples to false do up to sqrt of n only do if j is a prime start with 2j as j is prime set all multiples to false Method to validate input public void checkArgs String args throws Exception Check arguments for correct number of parameters if args.length 1 throw new Exception else Get integer from character Integer num Integer.valueOf args O input num.intValue 216 Appendix A If less than zero if input 0 If less than lower bounds throw new Exception else if input max If greater than upper bounds throw new Exception End check4Prime 2. check4PrimeTest.java Requires the JUnit API junit.jar To compile javac -classpath . junit.jar check4PrimeTest.java To run java -cp . junit.jar check4PrimeTest Examples Starting test. Time 0.01 OK 7 tests Test .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.