public int hashCode() {
int hashCode = 1;
for (E e : this)
hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
return hashCode;
}
class BuildCircle extends BuildShape
.String str1 = "Hello";
String str2 = "Hello";
// Какую концепцию проверяем?
// Это не просто проверка функции ListAll, это проверка какой-то концепции кода
// Варианты.
// 1. Пустой listAll() даёт пустой список.
// 2. Непустой listAll() даёт непустой список.
void testListAll() {
ArrayList<Product> productList = new ArrayList<Product>();
// Проводим поиск в списке — что в этот список вносится?
// И не будет ли физической зависимости тестов друг от друга?
// И для чего вообще нужен этот search, если мы listAll тестируем?
// Что такое ProductRepository и он вообще проверен?
when(this.productRepository.search((String) any())).thenReturn(productList);
// Ну, хорошо.
List<Product> actualListAllResult = this.productService.listAll("Keyword");
// Отказ, они не same: первый мы только что создали, а второй откуда-то пришёл.
assertSame(productList, actualListAllResult);
// Получается, что концепция — поиск, когда ничего не находится?
assertTrue(actualListAllResult.isEmpty());
verify(this.productRepository).search((String) any());
// Получается, единственная концепция, которую мы тестируем,— поиск в пустом списке даёт пустоту
// (и та некорректная из-за assertSame).
assertTrue(this.productService.getAll().isEmpty());
}
class Button {
protected void paint(Canvas aCanvas) {}
}
class MyButton extends Button {
@Override
protected void paint(Canvas aCanvas) {}
}
interface Button {
void press();
boolean state();
void addListener(ButtonListener x);
}
class GameObject {
void paint(Renderer renderer);
}
class MyButton extends GameObject implements Button {
}
class FridgeGame implements ButtonListener { // помните, такая была в «Братьях Пилотах»?
Button buttons[][] = new MyButton[4][4];
}
boolean[][] visited = new boolean[ROW][COL];
static final byte DIR_UNKNOWN = 0;
static final byte DIR_UP = 1;
...
byte[][] bestDirection = new boolean[ROW][COL]; // изначально заполнено DIR_UNKNOWN
for (int dir = DIR_UP; dir <= DIR_RIGHT; ++dir) {
...
bestDirection[row][col] = dir;
}
std::wstring xl::colNameW(
size_t aIndex)
{
wchar_t q[21]; // more than enough even for 64-bit system :)
wchar_t* ptr = q + 20;
*ptr = 0; // debug
// Getting size
size_t n = 1;
unsigned long long pw = 26;
while (aIndex>=pw && n<20)
{
aIndex -= static_cast<size_t>(pw);
pw *= 26;
++n;
}
FOR_S(i, 0, n) // макрос, означающий for (size_t i = 0; i < n; ++i)
{
*(--ptr) = static_cast<wchar_t>(L'A' + (aIndex % 26));
aIndex /= 26;
}
return std::wstring(ptr, n);
}
namespace {
bool isCap(const char* x, const char* aEnd)
{
return (x != aEnd && *x >= 'A' && *x <= 'Z');
}
bool isDig(const char* x, const char* aEnd)
{
return (x != aEnd && *x >= '0' && *x <= '9');
}
} // anon namespace
xl::CellCoords xl::parseCellCoords(
const char* aStart, const char* aEnd)
{
enum {
AA = 26,
AAA = 26 + 26 * 26
};
xl::CellCoords r;
// Letter
r.col = 0;
if (!isCap(aStart, aEnd))
return CellCoords::bad();
r.col = *(aStart++) - 'A';
if (isCap(aStart, aEnd)) {
r.col = (r.col * 26) + *(aStart++) - 'A';
if (isCap(aStart, aEnd)) {
r.col = AAA + (r.col * 26) + *(aStart++) - 'A';
} else {
r.col += AA;
}
}
// Number
r.row = 0;
while (isDig(aStart, aEnd)) {
size_t r0 = r.row;
r.row = r.row * 10 + *(aStart++) - '0';
if (r.row < r0)
return CellCoords::bad();
}
if (r.row == 0 || aStart != aEnd)
return CellCoords::bad();
--r.row;
return r;
}