Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
niksoc-hi committed Feb 11, 2019
1 parent e35ff55 commit f099bbc
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 17 deletions.
41 changes: 41 additions & 0 deletions spec/AllocationManagerImpl.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Allocation from '../src/Allocation';
import AllocationManagerImpl from '../src/AllocationManagerImpl';
import ArrayModelStore from '../src/ArrayModelStore';
import Developer from '../src/Developer';
import Project from '../src/Project';
import Technology from '../src/Technology';

describe('AllocationManagerImpl', function () {
describe('getFreeDevelopersForTechnology', function () {
it('should give empty array when no developer exists for technology', function () {
const developerStore = new ArrayModelStore<Developer>();
const projectStore = new ArrayModelStore<Project>();
const allocationStore = new ArrayModelStore<Allocation>();
const alloc_manager = new AllocationManagerImpl(projectStore, developerStore, allocationStore);

const freeDevelopersForJava = alloc_manager.getFreeDevelopersForTechnology(Technology.JAVA);

expect(freeDevelopersForJava).toEqual([]);
});
});

describe('getFreeDevelopersForTechnology', function () {
it('should give free developers for technology', function () {
const developerStore = new ArrayModelStore<Developer>();
developerStore.add(new Developer({ id: 1, name: 'Kick', knownTechnologies: [Technology.JAVA] }));
developerStore.add(new Developer({ id: 2, name: 'Nick', knownTechnologies: [Technology.JAVA] }));

const projectStore = new ArrayModelStore<Project>();
const allocationStore = new ArrayModelStore<Allocation>();
const alloc_manager = new AllocationManagerImpl(projectStore, developerStore, allocationStore);

const freeDevelopersForJava = alloc_manager.getFreeDevelopersForTechnology(Technology.JAVA);

expect(freeDevelopersForJava).toEqual([
new Developer({ id: 1, name: 'Kick', knownTechnologies: [Technology.JAVA] }),
new Developer({ id: 2, name: 'Nick', knownTechnologies: [Technology.JAVA] }),
]);
});
});

});
3 changes: 0 additions & 3 deletions src/AllocationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ export default interface AllocationManager {
getFreeDevelopersForTechnology(technology: Technology): Developer[];
allocateDeveloperToProjectForTechnology(developer: Developer, project: Project, technology: Technology): void;
}



19 changes: 11 additions & 8 deletions src/AllocationManagerImpl.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
import Allocation from './Allocation';
import AllocationManager from './AllocationManager';
import Developer from './Developer';
import ModelStore from './ModelStore';
import Project from './Project';
import { allocationStore, developerStore, projectStore } from './stores';
import Technology from './Technology';

export default class AllocationManagerImpl implements AllocationManager {

constructor() { }
constructor(
private projectStore: ModelStore<Project>,
private developerStore: ModelStore<Developer>,
private allocationStore: ModelStore<Allocation>) { }

getUnfulfilledRequirementsForProject(projectId: number): Technology[] {
const requiredTechnologies = projectStore.getById(projectId).requiredTechnologies;
const requiredTechnologies = this.projectStore.getById(projectId).requiredTechnologies;
const fulfilledTechnologies = new Set(this.getFulfilledRequirementsForProject(projectId));
return requiredTechnologies.filter(technology => !fulfilledTechnologies.has(technology));
}

getAllocatedDeveloperTechnologiesForProject(projectId: number): { developerId: number, technology: Technology }[] {
return allocationStore
return this.allocationStore
.filter(alloc => alloc.projectId === projectId)
.map(alloc => ({ developerId: alloc.developerId, technology: alloc.technology }));
}

getFreeDevelopersForTechnology(technology: Technology): Developer[] {
return developerStore
return this.developerStore
.filter(developer => developer.knownTechnologies.some(t => t === technology))
.filter(developer => !this.getAllocatedDeveloperIds().some(id => id === developer.id));
}

allocateDeveloperToProjectForTechnology(developer: Developer, project: Project, technology: Technology): void {
allocationStore.add(new Allocation(developer.id, project.id, technology));
this.allocationStore.add(new Allocation(developer.id, project.id, technology));
}

private getAllocatedDeveloperIds(): number[] {
return allocationStore.all().map(developer => developer.id);
return this.allocationStore.all().map(developer => developer.id);
}

private getFulfilledRequirementsForProject(projectId: number): Technology[] {
return allocationStore
return this.allocationStore
.filter(alloc => alloc.projectId === projectId)
.map(alloc => alloc.technology);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Developer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ import Technology from './Technology';
export default class Developer extends Model {
name: string;
knownTechnologies: Technology[];

constructor(obj?: Partial<Developer>) {
super();
Object.assign(this, obj);
}
}
6 changes: 5 additions & 1 deletion src/Technology.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
type Technology = string;
enum Technology {
JAVA,
PYTHON,
JAVASCRIPT,
}

export default Technology;
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Developer from "./Developer";
import { developerStore } from "./stores";
import Technology from "./Technology";

const d = new Developer();

d.id = 1;
d.knownTechnologies = ['java', 'python'];
d.knownTechnologies = [Technology.JAVA, Technology.PYTHON];

developerStore.add(d);

Expand Down
10 changes: 6 additions & 4 deletions src/mockData.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import Technology from './Technology';

const MOCK_DATA = {
DEVELOPERS: [
{
id: 1,
name: 'Kick Buttowski',
knownTechnologies: ['java', 'python', 'javascript'],
knownTechnologies: [Technology.JAVA, Technology.PYTHON, Technology.JAVASCRIPT],
},
{
id: 2,
name: 'Courage C.D',
knownTechnologies: ['python'],
knownTechnologies: [Technology.PYTHON],
},
],
PROJECTS: [
{
id: 1,
requiredTechnologies: ['java']
requiredTechnologies: [Technology.JAVA]
},
{
id: 2,
requiredTechnologies: ['python', 'javascript']
requiredTechnologies: [Technology.PYTHON, Technology.JAVASCRIPT]
}
]
};
Expand Down

0 comments on commit f099bbc

Please sign in to comment.