Посмотрите, пожалуйста, кто решил. Вроде перепроверил все и тесты написал, но все же валидатор уперся и молвит: "Программа не прошла тестирование". Скриншоты с пройденными тестами выложить не дали, сказали, что маловат еще:) Взгляните на код и тесты, может у кого-нибудь есть идеи, что я делаю не так.

Метод revalidate() класса Advertisement:

public void revalidate() throws UnsupportedOperationException{
    if (hits <= 0) throw new UnsupportedOperationException();
    hits--;
    if (hits == 1) amountPerOneDisplaying += initialAmount % amountPerOneDisplaying;

}

Класс для его тестирования AdvertisementTest (Может кому пригодится)

public class AdvertisementTest {
    @Test
        public void testRevalidate() throws Exception {
            Object someContent = new Object();
            long initialAmount = 125;
            int hits = 3;
//hits = 3
            Advertisement advertisement = new Advertisement(someContent, "Test Video", initialAmount, hits, 3 * 60);
            int expectedHits = advertisement.getHits();
            advertisement.revalidate();
            int actualHits = advertisement.getHits();
            assertEquals(expectedHits - 1, actualHits);
//hits = 2
            long expectedAmountPerOneDisplaying = (initialAmount % hits) + advertisement.getAmountPerOneDisplaying();
            advertisement.revalidate();
            long actualAmountPerOneDisplaying = advertisement.getAmountPerOneDisplaying();
            assertEquals(expectedAmountPerOneDisplaying, actualAmountPerOneDisplaying);
//hits = 1
            actualAmountPerOneDisplaying = advertisement.getAmountPerOneDisplaying();
            advertisement.revalidate();
            expectedAmountPerOneDisplaying = advertisement.getAmountPerOneDisplaying();
            assertEquals(expectedAmountPerOneDisplaying, actualAmountPerOneDisplaying);
//hits = 0
            boolean flag = false;
            try {
                advertisement.revalidate();
            } catch (UnsupportedOperationException ignory) {
                flag = true;
            }
            assertTrue(flag);

    }

}

Класс DirectorTablet с реализованными методами и врапером для тестов

public class DirectorTablet {

    public void printAdvertisementProfit(){
        SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
        long total = 0;
        for(Map.Entry<Date, Long> pair : StatisticManager.getInstance().AdvertisementProfit().entrySet()){
            printMessage(String.format(Locale.ENGLISH, "%s - %.2f",
                    format.format(pair.getKey()),
                    pair.getValue() / 100.0));
            total += pair.getValue();
        }
        printMessage(String.format(Locale.ENGLISH, "Total - %.2f\r\n", total / 100.0));
    }
    public void printCookWorkloading(){
        SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
        for (Map.Entry<Date, Map<String, Integer>> date : StatisticManager.getInstance().CookWorkloading().entrySet()) {
            printMessage(format.format(date.getKey()));
            for (Map.Entry<String, Integer> cook : date.getValue().entrySet()) {
                printMessage(String.format(Locale.ENGLISH, "%s - %d min",
                        cook.getKey(),
                        cook.getValue() % 60 == 0? cook.getValue() / 60: cook.getValue() / 60 + 1));
            }
            ConsoleHelper.writeMessage("");
        }
    }
    public void printActiveVideoSet(){
    }
    public void printArchivedVideoSet(){
    }

    private void printMessage(String message){
        ConsoleHelper.writeMessage(message);
        outPutList.add(message);
    }

    //Для модуля тестов - Начало
    private List<String> outPutList = new ArrayList<>();
    public List<String> wPrintAdvertisementProfit() {
        outPutList = new ArrayList<>();
        printAdvertisementProfit();
        return outPutList;
    }
    public List<String> wPrintCookWorkloading() {
        outPutList = new ArrayList<>();
        printCookWorkloading();
        return outPutList;
    }
    //Для модуля тестов - Конец
}

Соответственно сам класс тестов DirectorTabletTest

public class DirectorTabletTest {
    @Test
    public void printAdvertisementProfit() throws Exception {
        StatisticManager manager = StatisticManager.getInstance();
        GregorianCalendar date = new GregorianCalendar();
        date.setTime(new Date("march 1 2015"));
        date.add(Calendar.DAY_OF_MONTH, -1);
        manager.register(new VideoSelectedEventDataRow(null, 1, 100, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 2, 200, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 3, 300, date.getTime()));
        date.add(Calendar.DAY_OF_MONTH, -1);
        manager.register(new VideoSelectedEventDataRow(null, 4, 400, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 5, 500, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 6, 900, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 7, 800, date.getTime()));
        date.add(Calendar.DAY_OF_MONTH, -1);
        manager.register(new VideoSelectedEventDataRow(null, 8, 700, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 9, 600, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 10, 500, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 11, 400, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 12, 300, date.getTime()));
        date.setTime(new Date("march 1 2016"));
        manager.register(new VideoSelectedEventDataRow(null, 8, 700, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 9, 600, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 10, 500, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 11, 400, date.getTime()));
        manager.register(new VideoSelectedEventDataRow(null, 12, 300, date.getTime()));
        List<String> list = new DirectorTablet().wPrintAdvertisementProfit();
        String actual = list.toString();
        String expected = "[01-Mar-2016 - 0.50, 28-Feb-2015 - 0.06, 27-Feb-2015 - 0.22, 26-Feb-2015 - 0.50, Total - 1.28\r\n]";
        assertEquals(expected, actual);
    }

    @Test
    public void printCookWorkloading() throws Exception {
        StatisticManager manager = StatisticManager.getInstance();
        GregorianCalendar date = new GregorianCalendar();
        date.setTime(new Date("march 1 2015"));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Amigo", 599, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Petrov", 20 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Ivanov", 30 * 60, null, date.getTime()));
        date.add(Calendar.DAY_OF_MONTH, -1);
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Amigo", 90 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Petrov", 80 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Ivanov", 70 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Amigo", 60 * 60, null, date.getTime()));
        date.add(Calendar.DAY_OF_MONTH, -1);
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Amigo", 50 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Petrov", 40 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Ivanov", 30 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Amigo", 20 * 60, null, date.getTime()));
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Petrov", 10 * 60, null, date.getTime()));
        date.add(Calendar.DAY_OF_MONTH, -1);
        manager.register(new CookedOrderEventDataRow("Tablet{number=4}", "Amigo", 50 * 60, null, date.getTime()));
        List<String> list = new DirectorTablet().wPrintCookWorkloading();
        String actual = list.toString();
        String expected = "[01-Mar-2015, Amigo - 10 min, Ivanov - 30 min, Petrov - 20 min, " +
                "28-Feb-2015, Amigo - 150 min, Ivanov - 70 min, Petrov - 80 min, " +
                "27-Feb-2015, Amigo - 70 min, Ivanov - 30 min, Petrov - 50 min, " +
                "26-Feb-2015, Amigo - 50 min]";
        assertEquals(expected, actual);

    }

}

Ну и класс StatisticManager public class StatisticManager { private static StatisticManager ourInstance = new StatisticManager(); private StatisticStorage storage = new StatisticStorage(); private Set<cook> set = new HashSet<>();

    public static StatisticManager getInstance() {
        return ourInstance;
    }

    private StatisticManager() {
    }

    public void register(EventDataRow data){
        storage.put(data);
    }
    public void register(Cook cook){
        set.add(cook);
    }

    public Map<Date, Map<String, Integer>> CookWorkloading(){
        Map<Date, Map<String, Integer>> result = new TreeMap<>(Collections.<Date>reverseOrder());

        for (EventDataRow event : storage.getEvent(EventType.COOKED_ORDER)) {
            CookedOrderEventDataRow order = (CookedOrderEventDataRow)event;
            Date date = cleanTimeToDate(order.getDate());
            if(result.containsKey(date)){
                int dx = 0;
                if(result.get(date).containsKey(order.getCookName())){
                    dx = result.get(date).get(order.getCookName());
                }
                result.get(date).put(order.getCookName(), order.getTime() + dx);
            }
            else{
                result.put(date, new TreeMap<String, Integer>());
                result.get(date).put(order.getCookName(), order.getTime());
            }
        }

        return result;
    }

    private Date cleanTimeToDate(Date dateObject) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dateObject);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        long time = cal.getTimeInMillis();
        return dateObject;
    }

    public Map<Date, Long> AdvertisementProfit() {
        Map<Date, Long> result = new TreeMap<>(Collections.<Date>reverseOrder());
        for (EventDataRow eventDataRow : storage.getEvent(EventType.SELECTED_VIDEOS)) {
            VideoSelectedEventDataRow event = (VideoSelectedEventDataRow)eventDataRow;
            Date date = cleanTimeToDate(event.getDate());
            long dx = 0;
            if (result.containsKey(date))
                dx = result.get(date);
            result.put(date, event.getAmount() + dx);
        }

        return result;
    }

    private class StatisticStorage{
        private Map<EventType, List<EventDataRow>> map;

        private Map<EventType, List<EventDataRow>> getMap() {
            return map;
        }

        private StatisticStorage() {
            map = new HashMap<>();
            for (EventType event : EventType.values()){
                map.put(event, new ArrayList<EventDataRow>());
            }
        }

        private void put(EventDataRow data){
            map.get(data.getType()).add(data);
        }

        private List<EventDataRow> getEvent(EventType type){
            return map.get(type);
        }
    }

}

Буду благодарен любой помощи!

задан 13 Ноя '16, 12:03

%D0%93%D0%B0%D1%80%D0%B8%D0%BA%20%D0%9A%D1%80%D0%B0%D0%BC%D0%B5%D1%80's gravatar image

Гарик Крамер
111
одобрено: 0%

закрыто 13 Сен, 16:48

AndyRad's gravatar image

AndyRad
13.1k29

Вопрос был закрыт по следующей причине: "Problem is not reproducible or outdated" AndyRad 13 Сен, 16:48

Следить за вопросом

По Email:

После авторизации вы сможете подписаться на любые обновления здесь

Основы Markdown

  • *italic* or _italic_
  • **bold** or __bold__
  • ссылка:[текст](http://url.com/ "заголовок")
  • изображение?![alt текст](/path/img.jpg "заголовок")
  • нумерованный список: 1. Foo 2. Bar
  • Для того чтобы добавить разрыв строки просто добавьте два пробела.
  • основные HTML тэги, также поддерживаются

Тэги:

×3,805
×39
×3

Задан: 13 Ноя '16, 12:03

Просмотров: 175 раз

Отредактирован: 13 Сен, 16:48