Merge lp:~dobey/unity-scope-click/multistar into lp:unity-scope-click

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 446
Merged at revision: 456
Proposed branch: lp:~dobey/unity-scope-click/multistar
Merge into: lp:unity-scope-click
Diff against target: 103 lines (+52/-1)
4 files modified
libclickscope/click/utils.cpp (+23/-0)
libclickscope/click/utils.h (+1/-0)
libclickscope/tests/test_utils.cpp (+25/-0)
scope/clickstore/store-query.cpp (+3/-1)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/multistar
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Alejandro J. Cura (community) Approve
Review via email: mp+294019@code.launchpad.net

Commit message

Use 5 stars for visualizing the rating value.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

This should be moved to its own function, and needs some unit tests.

review: Needs Fixing
445. By dobey

Refactor to separate method with tests.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

We don't check whatever comes in the json for pkg.rating, so please add tests for -1.0 and 6.0.

review: Needs Fixing
446. By dobey

Bound the rating betwen 0.0 and 5.0 for star rendering.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks great

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libclickscope/click/utils.cpp'
--- libclickscope/click/utils.cpp 2014-07-25 22:06:11 +0000
+++ libclickscope/click/utils.cpp 2016-05-17 18:05:09 +0000
@@ -57,6 +57,29 @@
57 return s.str();57 return s.str();
58}58}
5959
60std::string click::Formatter::render_rating_stars(double rating)
61{
62 std::ostringstream ss;
63 int rounded;
64
65 // Only support values of rating between 0.0 and 5.0
66 if (rating < 0.0f) {
67 rounded = 0;
68 } else if (rating > 5.0f) {
69 rounded = 5;
70 } else {
71 rounded = round(rating);
72 }
73
74 for (int i = 0; i < rounded; i++) {
75 ss << "★";
76 }
77 for (int j = 0; j < 5 - rounded; j++) {
78 ss << "☆";
79 }
80 return ss.str();
81}
82
60using namespace boost::posix_time;83using namespace boost::posix_time;
6184
62time_input_facet* build_input_facet(std::stringstream& ss)85time_input_facet* build_input_facet(std::stringstream& ss)
6386
=== modified file 'libclickscope/click/utils.h'
--- libclickscope/click/utils.h 2014-07-25 05:35:28 +0000
+++ libclickscope/click/utils.h 2016-05-17 18:05:09 +0000
@@ -55,6 +55,7 @@
55{55{
56public:56public:
57 static std::string human_readable_filesize(long num_bytes);57 static std::string human_readable_filesize(long num_bytes);
58 static std::string render_rating_stars(double rating);
58};59};
5960
60} // namespace click61} // namespace click
6162
=== modified file 'libclickscope/tests/test_utils.cpp'
--- libclickscope/tests/test_utils.cpp 2014-07-25 20:25:49 +0000
+++ libclickscope/tests/test_utils.cpp 2016-05-17 18:05:09 +0000
@@ -92,6 +92,31 @@
92 ASSERT_EQ(click::Formatter::human_readable_filesize(42*1024*1024+512*1024+512), "42.5 MiB");92 ASSERT_EQ(click::Formatter::human_readable_filesize(42*1024*1024+512*1024+512), "42.5 MiB");
93}93}
9494
95TEST_F(UtilsTest, testRatingStarsFull)
96{
97 ASSERT_EQ(click::Formatter::render_rating_stars(2.0f), "★★☆☆☆");
98}
99
100TEST_F(UtilsTest, testRatingStarsHalf)
101{
102 ASSERT_EQ(click::Formatter::render_rating_stars(3.5f), "★★★★☆");
103}
104
105TEST_F(UtilsTest, testRatingStarsQuarter)
106{
107 ASSERT_EQ(click::Formatter::render_rating_stars(3.25f), "★★★☆☆");
108}
109
110TEST_F(UtilsTest, testRatingStarsNegative)
111{
112 ASSERT_EQ(click::Formatter::render_rating_stars(-1.0f), "☆☆☆☆☆");
113}
114
115TEST_F(UtilsTest, testRatingStarOverload)
116{
117 ASSERT_EQ(click::Formatter::render_rating_stars(6.0f), "★★★★★");
118}
119
95class TestableDate : public click::Date120class TestableDate : public click::Date
96{121{
97public:122public:
98123
=== modified file 'scope/clickstore/store-query.cpp'
--- scope/clickstore/store-query.cpp 2016-05-10 14:56:11 +0000
+++ scope/clickstore/store-query.cpp 2016-05-17 18:05:09 +0000
@@ -35,6 +35,7 @@
35#include <click/key_file_locator.h>35#include <click/key_file_locator.h>
36#include <click/qtbridge.h>36#include <click/qtbridge.h>
37#include <click/departments-db.h>37#include <click/departments-db.h>
38#include <click/utils.h>
3839
39#include <unity/scopes/Annotation.h>40#include <unity/scopes/Annotation.h>
40#include <unity/scopes/CategoryRenderer.h>41#include <unity/scopes/CategoryRenderer.h>
@@ -298,7 +299,8 @@
298 std::string price = _("FREE");299 std::string price = _("FREE");
299 std::stringstream ss;300 std::stringstream ss;
300 ss << std::fixed << std::setprecision(1);301 ss << std::fixed << std::setprecision(1);
301 ss << "☆ " << pkg.rating;302 ss << click::Formatter::render_rating_stars(pkg.rating);
303 ss << " " << pkg.rating;
302 std::string rating{ss.str()};304 std::string rating{ss.str()};
303305
304 bool was_purchased = false;306 bool was_purchased = false;

Subscribers

People subscribed via source and target branches

to all changes: