Question
package com.spartasystems.interview; public class FloorPlan { private final int width; private final int length; public FloorPlan(int length, int width){ this.width = width; this.length = length;
package com.spartasystems.interview;
public class FloorPlan {
private final int width; private final int length;
public FloorPlan(int length, int width){ this.width = width; this.length = length; } }
package com.spartasystems.interview;
import java.util.ArrayList; import java.util.List; import java.util.Map;
public class FloorPlanUtility {
/** * Given a map of building names and floor plans and a number 'n', * return a list of 'n' building names that were mapped to the * FloorPlans with the largest areas * * Things to consider: * * - The output does not need to be sorted * - Inputs need to be validated to pass all unit tests (throw InvalidArgumentException) * * * @param buildings a map of building name -> floor plan * @param n the number of buildings with the largest floor plans to return * @return a List of building names with the largest floor plans */ public static List
return new ArrayList<>(); } }
Testclass:
package com.spartasystems.interview;
import org.hamcrest.Matchers; import org.junit.Test;
import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue;
public class FloorPlanUtilityTest {
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenInputMapIsNull() { FloorPlanUtility.largestNBuildings(null, 10); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenInputMapIsEmpty() { FloorPlanUtility.largestNBuildings(new HashMap<>(), 0); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenInputCountIsNegative() { Map
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenInputCountIsTooLarge() { // TODO }
@Test public void testLargestBuildings() { Map
List
List
assertThat(result, Matchers.notNullValue()); assertThat(result.size(), Matchers.equalTo(expected.size())); assertTrue(result.containsAll(expected)); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started