-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement mechanism to validate if driver is implemented correctly
- Loading branch information
1 parent
6ca3d99
commit a98f3fa
Showing
11 changed files
with
137 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** @namespace types */ | ||
|
||
const TAG = 'TunedAngle'; | ||
|
||
/** | ||
* Tunable angle. Angle is chosen depends on table name in configuration. | ||
* | ||
* @author Darko Lukic <lukicdarkoo@gmail.com> | ||
* @memberof types | ||
* @example | ||
* new TunePoint( | ||
* 150, 129, | ||
* [151, 129, 'table_1'], | ||
* [148, 128, 'table_2'] | ||
* ); | ||
*/ | ||
class TunedAngle { | ||
/** | ||
* Add multiple Points, add Points for each table. It must has | ||
* at least one Point which will be used as default. Other Points | ||
* must have tag! | ||
* | ||
* @param defaultX {integer} - Default point X coordinate | ||
*/ | ||
constructor(defaultAngle) { | ||
// If there are table dependent points | ||
for (let i = 1; i < arguments.length; i++) { | ||
|
||
// Check if the argument is valid | ||
if (typeof arguments[i][0] === 'undefined' || | ||
typeof arguments[i][1] === 'undefined') { | ||
|
||
Mep.Log.warn(TAG, 'Invalid arguments'); | ||
continue; | ||
} | ||
|
||
// Check if table name matches | ||
if (Mep.Config.get('table') == arguments[i][1]) { | ||
this.point = arguments[i][0]; | ||
} | ||
} | ||
|
||
// Otherwise use default point | ||
if (typeof this.point === 'undefined') { | ||
this.angle = defaultAngle; | ||
} | ||
} | ||
|
||
/** | ||
* Get angle depending on the chosen table in configuration. | ||
* | ||
* @returns {number} - Point | ||
*/ | ||
getAngle() { | ||
return this.angle; | ||
} | ||
} | ||
|
||
module.exports = TunedAngle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* A goal of the class is to check if drivers are correctly implemented. | ||
* | ||
* @author Darko Lukic <lukicdarkoo@gmail.com> | ||
* @memberOf utils | ||
*/ | ||
|
||
class DriverChecker { | ||
static check(driver) { | ||
let groups; | ||
if (typeof driver.getGroups === 'function') { | ||
groups = driver.getGroups(); | ||
} else { | ||
throw TypeError(driver.constructor.name + ' doesn\'t have member getGroups()'); | ||
} | ||
|
||
for (let group of groups) { | ||
switch (group) { | ||
case 'position': | ||
DriverChecker._checkPosition(driver); | ||
break; | ||
|
||
case 'terrain': | ||
DriverChecker._checkTerrain(driver); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
static _checkPosition(driver) { | ||
let driverClassName = driver.constructor.name; | ||
|
||
// Check getPosition() | ||
if (typeof driver.getPosition !== 'function') { | ||
throw TypeError(driverClassName + ' requires method getPosition()'); | ||
} | ||
if (driver.getPosition().constructor.name !== 'Point') { | ||
throw TypeError('Method '+ driverClassName +'.getPosition() must return Point'); | ||
} | ||
} | ||
|
||
static _checkTerrain(driver) { | ||
|
||
} | ||
} | ||
|
||
module.exports = DriverChecker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters