├── .gitignore ├── .travis.yml ├── Readme.md ├── js └── list.js ├── karma.conf.js ├── package.json ├── quz └── quz.js └── test └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | 5 | addons: 6 | chrome: stable 7 | 8 | services: 9 | - xvfb 10 | 11 | before_script: 12 | - "export DISPLAY=:99.0" 13 | 14 | before_install: 15 | npm install karma-cli -g -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # 作业 2 | 3 | ### 步骤 4 | 5 | * fork 代码 6 | * 修改代码跑通测试 7 | * 将代码提交回主干仓库,让代码通过CI测试 -------------------------------------------------------------------------------- /js/list.js: -------------------------------------------------------------------------------- 1 | /** 2 | * List 3 | * @author donaldyang 4 | */ 5 | 6 | function List(head, tail) { 7 | this.head = head || 0; 8 | this.tail = tail || null; 9 | } 10 | 11 | // Returns a new List containing the array. 12 | List.list = function (array) { 13 | var sentinel = new List(), 14 | len = array.length, 15 | p, i; 16 | 17 | p = sentinel; 18 | for (i = 0; i < len; i++) { 19 | p.tail = new List(array[i]); 20 | p = p.tail; 21 | } 22 | return sentinel.tail; 23 | } 24 | 25 | // Returns a readable String for THIS. 26 | List.prototype.toString = function () { 27 | var res = '', L; 28 | res += '['; 29 | for (L = this; L !== null; L = L.tail) { 30 | res = res + ' ' + L.head; 31 | } 32 | res += ' ]'; 33 | return res; 34 | }; 35 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | // Generated on Fri Aug 04 2017 20:53:38 GMT+0800 (CST) 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | 7 | // base path that will be used to resolve all patterns (eg. files, exclude) 8 | basePath: '', 9 | 10 | 11 | // frameworks to use 12 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 13 | frameworks: ['mocha'], 14 | 15 | 16 | // list of files / patterns to load in the browser 17 | files: [ 18 | 'node_modules/should/should.js', 19 | 'js/*.js', 20 | 'quz/*.js', 21 | 'test/*.js' 22 | ], 23 | 24 | 25 | // list of files to exclude 26 | exclude: [ 27 | ], 28 | 29 | 30 | // preprocess matching files before serving them to the browser 31 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 32 | preprocessors: { 33 | }, 34 | 35 | 36 | // test results reporter to use 37 | // possible values: 'dots', 'progress' 38 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 39 | reporters: ['progress'], 40 | 41 | 42 | // web server port 43 | port: 9876, 44 | 45 | 46 | // enable / disable colors in the output (reporters and logs) 47 | colors: true, 48 | 49 | 50 | // level of logging 51 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 52 | logLevel: config.LOG_INFO, 53 | 54 | 55 | // enable / disable watching file and executing tests whenever any file changes 56 | autoWatch: true, 57 | 58 | 59 | // start these browsers 60 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 61 | browsers: ['Chrome_without_security'], 62 | 63 | customLaunchers: { 64 | Chrome_without_security: { 65 | base: 'Chrome', 66 | flags: ['--disable-web-security'] 67 | } 68 | }, 69 | 70 | 71 | // Continuous Integration mode 72 | // if true, Karma captures browsers, runs the tests and exits 73 | singleRun: true, 74 | 75 | // Concurrency level 76 | // how many browser should be started simultaneous 77 | concurrency: Infinity 78 | }) 79 | } 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "homework1", 3 | "version": "0.0.1", 4 | "description": "test", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "karma start" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/FE-star/homework1.git" 12 | }, 13 | "keywords": [ 14 | "test" 15 | ], 16 | "author": "Daniel Yang", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/FE-star/homework1/issues" 20 | }, 21 | "homepage": "https://github.com/FE-star/homework1#readme", 22 | "devDependencies": { 23 | "karma": "^1.7.0", 24 | "karma-chrome-launcher": "^2.2.0", 25 | "karma-mocha": "^1.3.0", 26 | "mocha": "^3.5.0", 27 | "should": "^11.2.1" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /quz/quz.js: -------------------------------------------------------------------------------- 1 | /** 2 | * dcate 3 | * A list consisting of elements of A followed by the 4 | * elements of B. May modify items of A. 5 | * Don't use 'new' 6 | * @param {List} A 7 | * @param {List} B 8 | * @returns {List} 9 | */ 10 | function dcate(A, B) { 11 | /** Fill in here **/ 12 | } 13 | 14 | /** 15 | * sub 16 | * The sublist consisting of LEN items from list L, 17 | * beginning with item #START (where the first item is #0). 18 | * Does not modify the original list elements. 19 | * it is an error if the desired items don't exist. 20 | * @param {List} L 21 | * @param {Number} start 22 | * @param {Number} len 23 | * @returns {List} 24 | */ 25 | function sub(L, start, len) { 26 | /** Fill in here **/ 27 | } 28 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | describe('unit test for quz.js', function () { 2 | 3 | var A = List.list([4, 6, 7, 3, 8]), 4 | B = List.list([3, 2, 5, 9]), 5 | C = List.list([19, 8, 7, 3, 2]); 6 | 7 | describe('#dcate()', function () { 8 | it('should get a list consisting of elements of A followed by the elements of B', function () { 9 | A.toString().should.equal('[ 4 6 7 3 8 ]'); 10 | dcate(A, B).toString().should.equal('[ 4 6 7 3 8 3 2 5 9 ]'); 11 | A.toString().should.not.equal('[ 4 6 7 3 8 ]'); 12 | }); 13 | }); 14 | 15 | describe('#sub()', function () { 16 | it('should get the sublist consisting of LEN items from list L', function () { 17 | C.toString().should.equal('[ 19 8 7 3 2 ]'); 18 | sub(C, 3, 2).toString().should.equal('[ 3 2 ]'); 19 | C.toString().should.equal('[ 19 8 7 3 2 ]'); 20 | }); 21 | }); 22 | 23 | }); --------------------------------------------------------------------------------