Software testing--determining phone numbers in detail


软件测试作业--电话号码

This article is all manual, and the business feels okay. There are still many businesses that I don’t know about, but the general mobile phone number and the general route of the landline are there. The code does not use any advanced knowledge, 勿喷it took more than 4 hours to complete, from finding information to writing basic java code, and then testing them one by one, sharing them, I hope it will be useful to everyone.

1. Job requirements

  1. Enter digits 1-15 first.
  2. It is required to determine the type of the phone number.
  3. For a landline, it is required to output the location of the landline number.
  4. For a mobile phone, it is required to output the type of the mobile phone number.
  5. The output adds the location of the mobile phone. (Add points)
  6. Identify foreign phone numbers. (Add points)

2. Demand Analysis

According to the requirements of the job, the following 5 requirements can be roughly analyzed. First, go to the Internet to find information and improve the requirements one by one. For software testing, it is necessary to consider as many test cases as possible.

1. Type of phone number

Telephone numbers can be divided into mobile phone numbers and landline numbers.

  • For the domestic landline analysis, the numbers starting with 0 or 8 are the landline numbers for the time being. Assuming that the landline numbers are excluded, the others are all mobile phone numbers, which can be subdivided from the mobile phone numbers.

  • The analysis here is not very comprehensive, and the analysis is a very large amount of work, which is carried out according to the needs of the operation.

2. Landline number and location

Landline format: area code + phone number

The international area code of mainland China is 86; the area code of Hong Kong Special Administrative Region is 852; the area code of Macao Special Administrative Region is 853; the area code of Taiwan Province is 886.

Here I take Jiangxi Province as an example. For others, you can refer to the comparison table of Chinese city telephone area codes.
Xinyu 0790 Nanchang 0791 Jiujiang 0792 Shangrao 0793 Linchuan 0794 Yichun 0795 Ji'an 0796
Ganzhou 0797 Jingdezhen 0798 Pingxiang 0799
Yingtan 0701

->中国城市电话区号对照表

China City Telephone Area Code Comparison Table (buyiju.com)

<-

3. Types of mobile phone numbers

Common Carriers

**China Mobile number range:**134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 172, 178, 182, 183, 184, 187, 188, 195, 197, 198

**China Unicom number segment:**130, 131, 132, 145, 155, 156, 166, 175, 176, 185, 186, 196

**China Telecom signal section:**133, 149, 153, 180, 181, 189, 173, 177, 190, 191, 193, 199

**China radio and television number segment: **192

Virtual carrier number segment

**Unicom:**167, 170(4,7,8,9), 171

**Telecom:**162, 170(0,1,2)

**Move:**165, 170(3,5,6)

IoT segment

**Unicom:**1400, 146

** Telecom: **1410

**MOVE:**1440, 148

satellite phone number

**Telecom:**1349, 174(00-05)

**Ministry of Industry and Information Technology Emergency Communication: **174(06-12)

** Maritime Satellite Communications: ** 1749

Other numbers

** Telecom service number: **10

**International collect call: **108

** Telecom Service Center: **10000

**Unicom Service Center: **100001

**Special beginning: **11 (such as: 110-alarm, 114-number inquiry, 119-fire alarm)

**Civil special number:**12 (such as: 120-emergency call, 121-weather forecast, 122-traffic accident warning)

4. Mobile location

Since each region has its own operator, and the operator has a unique number segment, it is a large amount of work to mention a region.

Here we take a part of China Mobile No. 182 in Yichun City, Jiangxi Province as an example. For others, please refer to the mobile phone number segment network below.
1829640 1829641 1829650 1829651 1829652 1829653 1829654 1829655 1829656 1829657 1829658 1829659 1829694 1829695

->江西宜春手机号段

Jiangxi Yichun mobile phone number section Daquan - Mobile phone number section network (uutool.cn)

<-

5. Foreign numbers

Commonly used numbers in China —> 11 digits

USA, Germany India, Switzerland, Netherlands, Belgium, France, Australia etc —> 10 places

New Zealand, Thailand, etc. —> 9 bits

Singapore —> 8 bits

Canada —> 7th place

6. Test cases

  1. For format validation, the input is a number.
  2. To verify the number of characters in the number, the input is 1-15 digits.
  3. Test the other numbers with various digits one by one.
  4. Validation against correct numbers, thresholds, etc.

3. Code writing

Write and test the above requirements in the main class with java code in turn. Because it is just an operation, not a business, it is a bit unfriendly to users. If it is not input into the corresponding format, it has to be re-run. The approximate mobile phone number and landline There are all routes, and Baidu has summarized many articles.

package softwaretest;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;

public class phoneTest {
    
    
    public static void main(String[] args) {
    
    
        /*
        * 1. 首先输入1-15位
        * */
        Scanner sc =  new Scanner(System.in);
        System.out.println("          判断电话号码            ");
        System.out.print("请重新输入"+"1-15"+"位电话号码:");
        String str = sc.nextLine();
        for (int i = 0; i < str.length(); i++) {
    
    
            if(str.charAt(i) < '0' || str.charAt(i) > '9'){
    
    
                System.out.print("格式错误,输入的不是数字");
                return;
            }else {
    
    
                continue;
            }
        }
        while (true){
    
    
            if(str.length() <= 1 || str.length() >= 15){
    
    //暗含判断是否为空
                System.out.print("输入的位数不符合,请重新输入"+"1-15"+"位电话号码:");
                str = sc.nextLine();
            } else {
    
    
                break;
            }
        }
        /*
        * 2.要求判断出电话号码的类型。
        * 电话号码可分为手机号码和座机号码
        * */
        //座机号码--以0或8开头--仅仅分析国内
        if(str.charAt(0) == '0'){
    
     // 0开头是国内省份
            String s = str.substring(0,4);
            /*
            * 3.对于座机,要求输出座机号码地点。
            * */
                switch (s){
    
    
                    case "0790":
                        System.out.println("江西省新余市");
                        return;
                    case "0791":
                        System.out.println("江西省南昌市 ");
                        return;
                    case "0792":
                        System.out.println("江西省九江市 ");
                        return;
                    case "0793":
                        System.out.println("江西省上饶市 ");
                        return;
                    case "0794":
                        System.out.println("江西省临川市 ");
                        return;
                    case "0795":
                        System.out.println("江西省宜春市");
                        return;
                    case "0796":
                        System.out.println("江西省吉安市");
                        return;
                    case "0797":
                        System.out.println("江西省赣州市");
                        return;
                    case "0798":
                        System.out.println("江西省景德镇");
                        return;
                    case "0799":
                        System.out.println("江西省萍乡市 ");
                        return;
                    case "0701":
                        System.out.println("江西省鹰潭市");
                        return;
                    default:
                        System.out.println("其它省份还在开发中……");
                        return;
            }
        } else if (str.charAt(0) == '8') {
    
     // 8开头的是国际区号或行政区或台湾省
            if (str.charAt(1)  == '6') {
    
    
                System.out.println("中国国际区号");
                return;
            }
            String s = str.substring(0, 3);
            switch (s) {
    
    
                case "852":
                    System.out.println("香港特别行政区");
                    return;
                case "853":
                    System.out.println("澳门特别行政区");
                    return;
                case "886":
                    System.out.println("台湾省");
                    return;
                default:
                    System.out.println("没有该省份的号码");
                    return;
            }
        }

        /*
        * 4. 对于手机,要求输出手机号码的种类。
        *    标准的手机号
        * */
        if(str.length() == 11) {
    
    
            //手机号码--以1开头
            if (str.charAt(0) == '1') {
    
    
                String s = str.substring(0, 3);
//                中国移动特殊第4位数
                if ("134".equals(s)) {
    
    
                    for (int i = 0; i < 9; i++) {
    
    
                        if (str.charAt(3) == i + '0') {
    
    
                            System.out.println("中国移动");
                            return;
                        }
                    }
                }
//           移动运营商
                String a[] = {
    
    "135", "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "172", "178", "182", "183", "184", "187", "188", "195", "197", "198"};
//           江西省宜春市的中国移动182号段
                String b[] = {
    
    "9640", "9641", "9650", "9651", "9652", "9653", "9654", "9655", "9656", "9657", "9658", "9659", "9694", "9695"};
                String s1 = str.substring(3, 7);
                for (int i = 0; i < a.length; i++) {
    
    
                    if (a[i].equals(s)) {
    
    
                        if (s.equals("182")) {
    
    
                            /*
                            * 5.手机地点仅仅以江西省宜春市的中国移动182号段为例
                            * */
                            for (int j = 0; j < b.length; j++) {
    
    
                                if (b[j].equals(s1)) {
    
    
                                    System.out.println("中国移动 江西省宜春市");
                                    return;
                                }
                                if(j == b.length - 1){
    
    
                                    System.out.println("中国移动");
                                    return;
                                }
                            }
                        } else {
    
    
                            System.out.println("中国移动");
                            return;
                        }
                    }
                }
//                中国联通
                String c[] = {
    
    "130", "131", "132", "145", "155", "156", "166", "175", "176", "185", "186", "196"};
                for (int i = 0; i < c.length; i++) {
    
    
                    if(c[i].equals(s)){
    
    
                        System.out.println("中国联通");
                        return;
                    }
                }

//                中国电信
                String d[] = {
    
    "133","149","153 ","180 ","181 ","189","173","177","190","191","193","199"};
                for (int i = 0; i < d.length; i++) {
    
    
                    if(d[i].equals(s)){
    
    
                        System.out.println("中国电信");
                        return;
                    }
                }

                String s2 = str.substring(0, 4);

//                虚拟运营商
//                中国联通虚拟运营商
                if(s.equals("167") || s.equals("171") || s2.equals("1704") || s2.equals("1707") || s2.equals("1708") || s2.equals("1709")){
    
    
                    System.out.println("中国联通虚拟运营商");
                    return;
                }
//                中国电信虚拟运营商
                if(s.equals("162") || s2.equals("1700") || s2.equals("1701") || s2.equals("1702")){
    
    
                    System.out.println("中国电信虚拟运营商");
                    return;
                }
//                中国移动虚拟运营商
                if(s.equals("165") || s2.equals("1703") || s2.equals("1705") || s2.equals("1706")){
    
    
                    System.out.println("中国移动虚拟运营商");
                    return;
                }

//                物联网号段
//                中国联通虚拟运营商
                if(s.equals("146") || s2.equals("1400")){
    
    
                    System.out.println("中国联通虚拟运营商");
                    return;
                }
//                中国移动虚拟运营商
                if(s.equals("148") || s2.equals("1440")){
    
    
                    System.out.println("中国移动虚拟运营商");
                    return;
                }
//                中国电信虚拟运营商
                if(s2.equals("1410")){
    
    
                    System.out.println("中国电信虚拟运营商");
                    return;
                }

                String s3 = str.substring(0,5);

//                电信卫星电话
                if(s3.equals("17400") || s3.equals("17401") || s3.equals("17402") || s3.equals("17403") || s3.equals("17404") || s3.equals("17405") || s2.equals("1349")){
    
    
                    System.out.println("电信卫星电话");
                    return;
                }

//                工信部应急卫星通信电话
                if(s3.equals("17406") || s3.equals("17407") || s3.equals("17408") || s3.equals("17409") || s3.equals("17410") || s3.equals("17411") || s3.equals("17412")){
    
    
                    System.out.println("工信部应急卫星通信电话");
                    return;
                }

//                海事卫星通信电话
                if(s2.equals("1749")){
    
    
                    System.out.println("海事卫星通信电话");
                    return;
                }

                System.out.println("其它手机号有待完善...");
                return;
            }else {
    
    
                System.out.print("根据您输入的,可以判断是判断手机号,但格式输入错误");
                return;
            }
        }

        /*
        * 6.判断国外的电话号码
        * */
        /*
         * 电话号码位数为10
         * */
        if(str.length() == 10){
    
    
            System.out.println("美国、德国印度、瑞士、荷兰、比利时、法国、澳大利亚等");
            return;
        }

        /*
         * 电话号码位数为9
         * */
        if(str.length() == 9){
    
    
            System.out.println("新西兰、泰国等 ");
            return;
        }

        /*
         * 电话号码位数为8
         * */
        if(str.length() == 8){
    
    
            System.out.println("新加坡");
            return;
        }
        if(str.length() == 8){
    
    
            System.out.println("加拿大");
            return;
        }

        /*
        * 电话号码位数为3
        * */
        if(str.length() == 3){
    
    
            String s = str.substring(0,3);
//                民用特殊号码
            if(s.equals("120")){
    
    
                System.out.println("急救电话");
                return;
            }
            if(s.equals("121")){
    
    
                System.out.println("天气预报");
                return;
            }
            if(s.equals("122")){
    
    
                System.out.println("交通事故告警");
                return;
            }

//        特种开头
            if(s.equals("110")){
    
    
                System.out.println("报警");
                return;
            }
            if(s.equals("114")){
    
    
                System.out.println("查号");
                return;
            }
            if(s.equals("119")){
    
    
                System.out.println("火警");
                return;
            }

//        国际对方付费电话
            if(s.equals("108")){
    
    
                System.out.println("国际对方付费电话");
                return;
            }
        }

        /*
         * 电话号码位数为2
         * */
        if(str.length() == 2){
    
    
            String s2 = str.substring(0,2);
//        电信服务服务号码
            if(s2.equals("10")){
    
    
                System.out.println("电信服务服务号码");
                return;
            }
        }

        /*
         * 电话号码位数为5
         * */
        if(str.length() == 5){
    
    
            String s3 = str.substring(0,5);
//        电信服务中心
            if(s3.equals("10000")){
    
    
                System.out.println("电信服务中心");
                return;
            }
        }

        /*
         * 电话号码位数为6
         * */
        if(str.length() == 6){
    
    
            String s4 = str.substring(0,6);
//        联通服务中心
            if(s4.equals("100001")){
    
    
                System.out.println("联通服务中心");
                return;
            }
        }

        System.out.println("其它号码还未完善...");
        return;
    }
}

记录每一个学习瞬间

Guess you like

Origin blog.csdn.net/qq_51601665/article/details/129777653