Network Analyzer is a program that processes network relationships between partners, companies, and employees. It reads commands from a file and prints out the companies' strongest relationships.
To build this program, you'll need Node.js installed on your system.
-
Clone the repository:
git clone https://github.com/username/network-analyzer.git
-
Navigate to the directory:
cd network-analyzer
-
Install the dependencies:
npm install
You can run the program by executing the following command:
node start input.txt
Replace input.txt
with the path to the file containing the text you want to process.
To run the tests, use the following command:
npm test
The problem was approached by defining classes to represent partners, companies, and employees and encapsulating their relationships and interactions. The NetworkAnalyzer
class is responsible for processing commands and performing the relationship analysis.
- Class Design: Classes were created to make the code more modular and easier to read.
- Command Processing: Commands are processed line by line from the provided file, allowing easy extendability for additional command types. This also allows us to process the file line by line instead of loading the entire file into memory.
- Analyzing Relationships: Relationships are analyzed and printed at the end of processing to determine the strongest relationship for each company. Having the printing functionality isolated from the file processing allows us to output the results in different formats in the future. For example, we could print the results to a file instead of the console.
- Dependency Injection: Dependencies like the file reader and console were injected instead of relying on global dependencies. This way, we can mock these during testing.
-
Assumptions about Input Data:
- The input file must follow the specific command format.
- Companies and Partners must be defined before Employees and Contacts.
- Employee names and company names are unique.
-
Possible Edge Cases:
- Handling of missing or malformed commands.
- Handling of duplicate commands for the same entity.