ThoughtWorks-成都信息工程学院创新实验室

补充测试+Git演示

2017-05-19  本文已影响10人  SW_BBK_兰天奇

更改后的main

/**
 * Created by lenovo on 2017/5/18.
 */
var test=function(){
};

test.prototype.sort=function(words) {
    var res = [];
    var p;
    var s=words;
    var ary = s.split(' ');
    ary.sort();
    if(words == '')
    {
        return "";
    }
    else
    {
    for(var i = 0;i<ary.length;)
    {
        var count = 0;
        for(var j=i;j<ary.length;j++)
        {
            if(ary[i] == ary[j])
            {
                count++;
            }
        }
        res.push([ary[i],count]);
        i+=count;
    }
//res 二维数维中保存了 值和值的重复数
    for(var x=0;x<res.length;x++) {
        for (var i = x; i < res.length; i++) {

            if (res[x][1] < res[i][1]) {
                var max=res[i];
                for (j = x; j < i; i--) {
                    res[i] = res[i - 1];
                }
                res[x] = max;
            }

        }
    }
    for(var i=0;i<res.length;i++)
    {
        console.log(res[i][0]+" "+res[i][1]+"\r\n");
        //document.writeln(res[i][0]+" "+res[i][1]+"<br/>");
    }
    }
}

module.exports = test;

测试代码

/**
 * Created by lenovo on 2017/5/18.
 */
var test = require("../lib/main");
describe("FrequencyN", function () {

     it("should return equal", function () {
            var result = new test();
         //noinspection JSUnresolvedFunction
         expect(result.sort("")).toEqual("");
        });
     it("should return one word one number", function () {
            var result = new test();
         //noinspection JSUnresolvedFunction
         expect(result.sort("he")).toEqual("he 1");
        });
     it("should return one word one number", function () {
            var result = new test();
         //noinspection JSUnresolvedFunction
         expect(result.sort("he is")).toEqual("he 1\r\nis 1");
        });
     it("should return one word one number", function () {
            var result = new test();
         //noinspection JSUnresolvedFunction
         expect(result.sort("he is is")).toEqual("is 2\r\nhe 1");
        })
     it("should return one word one number", function () {
            var result = new test();
         //noinspection JSUnresolvedFunction
         expect(result.sort("it was the age of wisdom it was the age of foolishness it is")).toEqual(
             "it 3\r\nwas 2\r\nthe 2\r\nage 2\r\nof 2\r\nwisdom 1\r\nfoolishness 1\r\nis 1");
        });

    });

Git练习

![7SVLED@8Z}UD]YRVRHB0P(O.png](http:https://img.haomeiwen.com/i5439747/e0b7eda6f4c6911e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![VK]@ZU8ZH03}4N8}]1~JFAH.png](http:https://img.haomeiwen.com/i5439747/589aed8fc04dd1a1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

ZRBV0GY4T3U$Q4{5(RN13YI.png
O7E~09EKR7GX86~~E%C%V}N.png
![LEJ66P6]LB@Y%RZPCTZ5`(Q.png](http:https://img.haomeiwen.com/i5439747/c0d68681ba6882d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
JG0DJ%WJAL@9V)ZSLV42VR7.png

Git上传到远程仓库

![)BY]4OB(5BGSYTH8Z1_{1}2.png](http:https://img.haomeiwen.com/i5439747/ae687e82b1a2c0fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

()GZ~_0%G@}$CKPUND9(TAS.png
{Y24T{BVU[YEH_QDBKC~QMO.png](http:https://img.haomeiwen.com/i5439747/e976a6aee96665a4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![]G(BQ{BDZ~8TX%76%R0WX97.png
上一篇 下一篇

猜你喜欢

热点阅读