示例#1
0
int is_in_free(modelica_metatype p)
{
  size_t i = 0, j = 0, k = 0;
  mmc_GC_page_type page = {0};

  for (k = 0; k < mmc_GC_state->mas.pages.current; k++)
  {
    page = mmc_GC_state->mas.pages.start[k];

    /* search in small */
    for (i = 0; i < MMC_GC_FREE_SIZES; i++)
    {
      for (j = 0; j < page.free->szSmall[i].current; j++)
      {
        if (is_in_range(p, page.free->szSmall[i].start[j], sizeof(modelica_metatype)*i))
        {
          return 1;
        }
      }
    }

    /* search in big */
    for (i = 0; i < page.free->szLarge.current; i++)
    {
      if (is_in_range(p, page.free->szLarge.start[i].start, page.free->szLarge.start[i].size * sizeof(modelica_metatype)))
      {
        return 1;
      }
    }
  }

  return 0;
}
示例#2
0
static int test_ramp_limit(void)
{
	system_load_current_ma = 3000;

	/* Plug in supplier that is limited to 1.6A */
	plug_charger(CHARGE_SUPPLIER_TEST7, 0, 500, 3000, 3000);
	usleep(SECOND);
	TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(charge_limit_ma == 1600);

	/* Switch to supplier that is limited to 2.4A */
	plug_charger(CHARGE_SUPPLIER_TEST8, 1, 500, 3000, 3000);
	usleep(SECOND);
	TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(charge_limit_ma == 2400);

	/* Go back to 1.6A limited, but VBUS goes low before that point */
	plug_charger(CHARGE_SUPPLIER_TEST7, 0, 500, 1200, 1300);
	usleep(SECOND);
	TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1000, 1200));

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
示例#3
0
static int test_overcurrent_after_switch_outlet(void)
{
	system_load_current_ma = 3000;
	/* Here's a less powerful charger */
	plug_charger(CHARGE_SUPPLIER_TEST5, 0, 500, 3000, 1500);
	usleep(SECOND * 5);

	/* Now the user decides to move it to a nearby outlet */
	unplug_charger();
	usleep(SECOND * 1.5);
	plug_charger(CHARGE_SUPPLIER_TEST5, 0, 500, 3000, 1500);

	/* Okay the user is satisified */
	while (task_wait_event(RAMP_STABLE_DELAY) == TASK_EVENT_OVERCURRENT) {
		/* Charger goes away but comes back after 0.6 seconds */
		unplug_charger();
		usleep(MSEC * 600);
		plug_charger(CHARGE_SUPPLIER_TEST5, 0, 500, 3000, 1500);
		usleep(CHARGE_DETECT_DELAY_TEST);
		/* Ramp restarts at 500 mA */
		TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	}

	TEST_ASSERT(is_in_range(charge_limit_ma, 1300, 1500));

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
示例#4
0
static int test_charge_port_change(void)
{
	system_load_current_ma = 3000;
	/* Start with a 1.5A ramp charge supplier on port 0 */
	plug_charger(CHARGE_SUPPLIER_TEST5, 0, 500, 1400, 1500);
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1200, 1400));

	/* Here comes a 2.1A ramp charge supplier on port 1 */
	plug_charger(CHARGE_SUPPLIER_TEST6, 0, 500, 2000, 2100);
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1800, 2000));

	/* Now we have a 2.5A non-ramp charge supplier on port 0 */
	plug_charger(CHARGE_SUPPLIER_TEST1, 0, 2500, 3000, 3000);
	usleep(SECOND);
	TEST_ASSERT(charge_limit_ma == 2500);
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(charge_limit_ma == 2500);

	/* Unplug on port 0 */
	plug_charger(CHARGE_SUPPLIER_TEST6, 0, 500, 2000, 2100);
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1800, 2000));

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
static BOOL mem_addr_legal(u32 addr, u32 size)
{
  u32 flash_b = 0;
  u32 flash_e = 0;
  u32 cache_mem_b = 0;
  u32 cache_mem_e = 0;
  u32 nc_mem_b = 0; // none cache memory begin
  u32 nc_mem_e = 0; // none cache memory end
  u32 reg_b = 0;
  u32 reg_e = 0;

  flash_b = get_flash_addr();
  flash_e = flash_b + CHARSTO_SIZE;

  cache_mem_b = 0x80000000;
  cache_mem_e = WHOLE_MEM_END & 0x8FFFFFFF;

  nc_mem_b = 0xa0000000;
  nc_mem_e = WHOLE_MEM_END;

  // FIXME:
  reg_b = 0xbf000000;
  reg_e = 0xbff00000; 

  if (is_in_range((u32)addr, size, flash_b, flash_e) ||
      is_in_range((u32)addr, size, cache_mem_b, cache_mem_e) ||
      is_in_range((u32)addr, size, nc_mem_b, nc_mem_e) ||
      is_in_range((u32)addr, size, reg_b, reg_e))
  {
    return TRUE;
  }
  
  return FALSE;
}
示例#6
0
static int test_partial_load(void)
{
	/* We have a 3A charger, but we just want 1.5A */
	system_load_current_ma = 1500;
	plug_charger(CHARGE_SUPPLIER_TEST4, 0, 500, 3000, 2500);

	/* We should end up with a little bit more than 1.5A */
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1500, 1600));

	/* Ok someone just started watching YouTube */
	system_load_current_ma = 2000;
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 2000, 2100));

	/* Somehow the system load increases again */
	system_load_current_ma = 2600;
	while (task_wait_event(RAMP_STABLE_DELAY) == TASK_EVENT_OVERCURRENT) {
		/* Charger goes away but comes back after 0.6 seconds */
		unplug_charger();
		usleep(MSEC * 600);
		plug_charger(CHARGE_SUPPLIER_TEST4, 0, 500, 3000, 2500);
		usleep(CHARGE_DETECT_DELAY_TEST);
		/* Ramp restarts at 500 mA */
		TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	}

	/* Alright the charger isn't powerful enough, so we'll stop at 2.5A */
	TEST_ASSERT(is_in_range(charge_limit_ma, 2300, 2500));

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
bool is_RECORD_CORRECT (const vector<string>& SETrecord, const vector<vector<vector<string> > >& DEF, size_t j, size_t k) {

	string actual_key = SETrecord.at(0);
	string list_key = DEF.at(j).at(0).at(0);

	if (actual_key != list_key) return false;

	string actual_value = capslock (SETrecord.at(1));
	string list_value = capslock (DEF.at(j).at(k).at(0));

	if (actual_key == "LINEWIDTH:" || actual_key == "STRESSANGLE:" || actual_key == "WELLINTERVAL_LENGTH:") {

		bool conv_has_failed = true;

		double min_value = string_to_double (DEF.at(j).at(k).at(1), conv_has_failed);
		double max_value = string_to_double (DEF.at(j).at(k).at(2), conv_has_failed);

		string_to_int (actual_value, conv_has_failed);

		if (actual_key == "LINEWIDTH:" && conv_has_failed) return false;

		if (actual_key == "STRESSANGLE:" && conv_has_failed) return false;

		if (actual_key == "WELLINTERVAL_LENGTH:" && conv_has_failed) return false;

		double value = string_to_double (actual_value, conv_has_failed);

		if (is_in_range(min_value, max_value, value) && !conv_has_failed) return true;
		else return false;
	}

	else if (actual_key == "CLUSTERNUMBER:") {

		if (actual_value == "A" || actual_value == "N") {

			if (actual_value == list_value) return true;
			else return false;
		}
		else {

			bool conv_has_failed = true;

			double min_value = string_to_double (DEF.at(j).at(k).at(1), conv_has_failed);
			double max_value = string_to_double (DEF.at(j).at(k).at(2), conv_has_failed);

			double value = string_to_double (actual_value, conv_has_failed);

			if (is_in_range(min_value, max_value, value) && !conv_has_failed) return true;
			else return false;
		}
	}
	else {

		if (actual_value == list_value) return true;
		else return false;
	}
}
示例#8
0
int collides(int action, int* board, int perform) {
    int x = 0;
    int y = 0;
    int collision = FALSE;
    int* move_modifier = NO_MOVE_VECTOR;
    int neighbour_x = 0;
    int neighbour_y = 0;

    for (int i=0; i<4; i++) {
        for (int j=0; j<4; j++) {
            if (action==LEFT) {
                move_modifier = LEFT_VECTOR;
            }
            if (action==UP) {
                move_modifier = UP_VECTOR;
            }
            if (action==RIGHT) {
                x = 3 - i;
                move_modifier = RIGHT_VECTOR;
            } else {
                x = i;
            }
            if (action==DOWN) {
                y = 3 - j;
                move_modifier = DOWN_VECTOR;
            } else {
                y = j;
            }

            neighbour_x = x - move_modifier[0];
            neighbour_y = y - move_modifier[1];

            int tile = 4 * y + x;

            if (is_in_range(neighbour_x, 0, 3) && is_in_range(neighbour_y, 0, 3)) {
                if (board[tile]==0) {
                    continue;
                }

                int neighbour_tile = 4 * neighbour_y + neighbour_x;

                if (board[neighbour_tile]==board[tile]) {
                    if (perform) {
                        board[tile] += 1;
                        board[neighbour_tile] = TILE_0_VALUE;
                    }
                    collision = TRUE;
                }
            }
        }
    }

    return collision;
}
示例#9
0
static status_t
find_image(const void* codePointer, image_info& _info)
{
	int32 cookie = 0;

	while (get_next_image_info(B_CURRENT_TEAM, &cookie, &_info) == B_OK) {
		if (codePointer == NULL ? _info.type == B_APP_IMAGE
				: (is_in_range(codePointer, _info.text, _info.text_size)
					|| is_in_range(codePointer, _info.data, _info.data_size))) {
			return B_OK;
		}
	}

	return B_ENTRY_NOT_FOUND;
}
示例#10
0
static int test_switch_outlet(void)
{
	int i;

	system_load_current_ma = 3000;
	/* Here's a nice powerful charger */
	plug_charger(CHARGE_SUPPLIER_TEST6, 0, 500, 3000, 3000);

	/*
	 * Now the user decides to move it to a nearby outlet...actually
	 * he decides to move it 5 times!
	 */
	for (i = 0; i < 5; ++i) {
		usleep(SECOND * 20);
		unplug_charger();
		usleep(SECOND * 1.5);
		plug_charger(CHARGE_SUPPLIER_TEST6, 0, 500, 3000, 3000);
		usleep(CHARGE_DETECT_DELAY_TEST);
		/* Ramp restarts at 500 mA */
		TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	}

	/* Should still ramp up to 3000 mA */
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(charge_limit_ma == 3000);

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
示例#11
0
void show_info(gfxsource_t*driver, char*filename)
{
    gfxdocument_t* pdf = driver->open(driver, filename);
    int pagenr;
    FILE*fo=0;
    if(!pdf) {
	msg("<error> Couldn't open %s", filename);
	exit(1);
    }
    if(outputname) {
	fo = fopen(outputname, "wb");
	if(!fo) {
	    perror(outputname);exit(1);;
	}
    } else {
	fo = stdout;
    }

    for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++) 
    {
	gfxpage_t*page = pdf->getpage(pdf,pagenr);
	if(is_in_range(pagenr, pagerange)) {
	    fprintf(fo, "page=%d width=%.2f height=%.2f\n", pagenr, page->width, page->height);
	}
    }
    pdf->destroy(pdf);
}
示例#12
0
static int test_fast_switch(void)
{
	int i;

	system_load_current_ma = 3000;
	plug_charger(CHARGE_SUPPLIER_TEST4, 0, 500, 3000, 3000);

	/*
	 * Here comes that naughty user again, and this time he's switching
	 * outlet really quickly. Fortunately this time he only does it twice.
	 */
	for (i = 0; i < 2; ++i) {
		usleep(SECOND * 20);
		unplug_charger();
		usleep(600 * MSEC);
		plug_charger(CHARGE_SUPPLIER_TEST4, 0, 500, 3000, 3000);
		usleep(CHARGE_DETECT_DELAY_TEST);
		/* Ramp restarts at 500 mA */
		TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	}

	/* Should still ramp up to 3000 mA */
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(charge_limit_ma == 3000);

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
  long_t Modelrangemanager::get_model_id(index gid)
{
  int left = -1;
  int right = modelranges_.size();
  assert(right >= 1);
  assert(is_in_range(gid));

  // to ensure thread-safety, use local range_idx
  size_t range_idx = right / 2;  // start in center
  while (!modelranges_[range_idx].is_in_range(gid))
  {
    if (gid > modelranges_[range_idx].get_last_gid())
    {
      left = range_idx;
      range_idx += (right - range_idx)/2;
    }
    else
    {
      right = range_idx;
      range_idx -= (range_idx - left)/2;
    }
    assert(left+1 < right);
    assert(range_idx < modelranges_.size());
  }
  return modelranges_[range_idx].get_model_id();
}
示例#14
0
	float Animator::_calculateValue(float k)
	{
		if (this->delay > 0.0f)
		{
			return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset);
		}
		float time = this->timer;
		if (this->isExpired())
		{
			if (this->reset)
			{
				return (this->discreteStep != 0 ? (float)((int)(this->offset / this->discreteStep) * this->discreteStep) : this->offset);
			}
			time = this->periods / habs(this->speed);
		}
		float result = 0.0f;
		switch (this->animationFunction)
		{
		case Object::Linear:
			result = time * this->speed * this->amplitude;
			break;
		case Object::Sine:
			result = (float)dsin(time * this->speed * 360) * this->amplitude;
			break;
		case Object::Square:
			result = (hmodf(time * this->speed, 1.0f) < 0.5f ? this->amplitude : -this->amplitude);
			break;
		case Object::Saw:
			result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 2 * this->amplitude;
			break;
		case Object::Triangle:
			result = hmodf(time * this->speed, 1.0f);
			if (!is_in_range(result, 0.25f, 0.75f))
			{
				result = (hmodf(time * this->speed + 0.5f, 1.0f) - 0.5f) * 4 * this->amplitude;
			}
			else
			{
				result = -(hmodf(time * this->speed - 0.25f, 1.0f) - 0.25f) * 4 * this->amplitude;
			}
			break;
		case Object::Random:
			result = hrandf(-this->speed * this->amplitude, this->speed * this->amplitude);
			break;
		case Object::Hover:
			if ((this->amplitude >= 0.0f) == this->parent->isCursorInside())
			{
				result = hmin(this->value - this->offset + k * this->speed, (float)habs(this->amplitude));
			}
			else
			{
				result = hmax(this->value - this->offset - k * this->speed, -(float)habs(this->amplitude));
			}
			break;
		case Object::Custom:
			result = (this->customFunction != NULL ? this->customFunction(this, time) : this->value);
			break;
		}
		return (this->discreteStep != 0 ? (float)((int)((result + this->offset) / this->discreteStep) * this->discreteStep) : (result + this->offset));
	}
struct ImageData rotate_image_shear(struct ImageData imageData, float degrees, int offsetX, int offsetY)
{
	const float radians = degrees * (float)(PI / 180.0f);
	struct ImageData newImageData = create_uninitialized_image(imageData.width, imageData.height);
	for (int y = 0; y < imageData.height; ++y)
	{
		for (int x = 0; x < imageData.width; ++x)
		{
			const int translatedX = x + offsetX;
			const int translatedY = y + offsetY;
			int xPrime, yPrime;
			//step 1 first shear
			xPrime = (int)(translatedX + translatedY * -tan(radians / 2));
			yPrime = translatedY;
			//step 2 second shear
			xPrime = xPrime;
			yPrime = (int)(xPrime * sin(radians) + yPrime);
			//step 3 third shear
			xPrime = (int)(xPrime + yPrime * -tan(radians / 2));
			yPrime = yPrime;

			const int targetX = xPrime - offsetX;
			const int targetY = yPrime - offsetY;
			if (is_in_range(newImageData, targetX, targetY))
				set_pixel_from_source(imageData, newImageData, x, y, targetX, targetY);
		}
	}
	return newImageData;
}
示例#16
0
文件: fight.c 项目: oitofelix/mininim
void
get_in_range (struct anim *k0, struct anim *k1, int r,
              bool only_k1, bool k1_dominant)
{
  struct anim *kd, *ks, *kl, *kr;

  kd = k1_dominant ? k1 : k0;
  ks = k1_dominant ? k0 : k1;

  kl = (kd->f.dir == LEFT) ? kd : ks;
  kr = (kd->f.dir == RIGHT) ? kd : ks;

  int i = 0;
  while (! is_in_range (k0, k1, r) && i <= (only_k1 ? 2 : 1) * r) {
    bool cl = kl == k0 && only_k1;
    bool cr = kr == k0 && only_k1;

    if (cl && cr) break;

    if (i++ % 2 && ! cl) {
      kl->fo.dx = -1;
      uncollide_front_fight (kl);
      next_frame (&kl->f, &kl->f, &kl->fo);
      kl->fo.dx = 0;
    } else if (! cr) {
      kr->fo.dx = -1;
      uncollide_front_fight (kr);
      next_frame (&kr->f, &kr->f, &kr->fo);
    }
  }
}
示例#17
0
// deallocate
void memory_pool::deallocate(void* address)
{
	//if NULL do nothing
	if( address == 0 )
		return;

	//assert the pointer is in range
	CRAP_ASSERT_DEBUG( is_in_range(address) == true, "Address for deallocation out of range" );

	//get block info
	memory_block* delete_block = (memory_block*) ((u8*)address - sizeof(memory_block));

	//parse previous block
	memory_block* previous_block = (memory_block*)(reinterpret_cast<u8*>(delete_block) - delete_block->offset_prev);

	//check if previous block is still in range
	CRAP_ASSERT_DEBUG( previous_block >= _block_start, "Previous offset of deallocation pointer out of range" );

	//crosscheck if data of previous block is correct
	bool check_offset = reinterpret_cast<memory_block*>(reinterpret_cast<u8*>(previous_block + 1) +
						previous_block->used_memory + previous_block->free_memory) == delete_block;

	// if crosscheck failed - abort
	CRAP_ASSERT_DEBUG( check_offset == true , "Offset check error, previous offset doesn't match" );

	//update free memory of previous block with complete size of deleted block
	previous_block->free_memory += sizeof(memory_block) + delete_block->used_memory + delete_block->free_memory;

	//update biggest free block
	update_biggest_block();
}
示例#18
0
文件: life.c 项目: dukelv/csci033
/* Function count_alive_neighbors

   Given a game board, array, and a row and column (row, col), determines the number of surrounding cells that are alive.
   If the cell is not on the game board, prints an error message and terminates the program.


   Input: int     rows  - the number of rows of the game board
          int     cols  - the number of columns of the game board
          int[][] array - the previous generation of the game board, a 2D array of zeros and ones
          int     row   - the row of the cell whose neighbors are being counted
          int     col   - the column of the cell whose neighbors are being counted

   Output: The number of surrounding cells that are alive
 */
int count_alive_neighbors(int rows, int cols, int array[rows][cols], int row, int col) {
    /* First, use an assert statement and call is_in_range to confirm the specified cell is on the game board. */
    assert(is_in_range(rows, cols, row, col));

    /* Then, assuming the assert succeeds:
         Compute and return the number of live neighbors by adding together the results of is_alive for each of
         the 8 surrounding cells.  Since is_alive checks to see if a cell is on the board, you do not need to do so here. */
    int counter = 0;
    int r, c;
    for(r=(row-1); r<=(row+1); r++)

    {
	for(c=(col-1); c<=(col+1); c++)
	{
	    if(is_alive(rows, cols, array, r, c))
	    {
		counter++;
	    }
	}
    }
    if(is_alive(rows, cols, array, row, col))
    {
	counter = counter-1;
    }
    return counter;
}
  int trap(int A[], int n) {
    stack<pair<int, int> > ranges;
    stack<int> bar_positions;

    for (int i = 0; i < n; ++i) {
      if (bar_positions.empty()) {
        bar_positions.push(i);
      }
      else {
        if (A[i] < A[bar_positions.top()]) {
          // 比栈顶元素小,继续压入。
          bar_positions.push(i);
        }
        else {
          int start;
          pair<int, int> range;

          while (!bar_positions.empty()) {
            start = bar_positions.top();

            if (A[start] > A[i]) {
              break;
            }

            // 弹出所有小于等于A[i]的元素
            bar_positions.pop();
          }

          // 注意,这里要分两种情况:
          // 1. A[start]被弹出,那么[start, i]正好构成一个区间,并且这之间的数一定小于A[start]。
          // 2. A[start]没有被弹出,[start, i]构成一个区间,并且有可能合并更多区间。
          bar_positions.push(i);
          range.first = start;
          range.second = i;

          while (!ranges.empty()) {
            // 可重叠的子区间弹出
            if (is_in_range(range, ranges.top())) {
              ranges.pop();
            }
            else {
              break;
            }
          }

          ranges.push(range);
        }
      }
    }

    int volume = 0;

    while (!ranges.empty()) {
      volume += calc_volume(A, ranges.top());
      ranges.pop();
    }

    return volume;
  }
示例#20
0
文件: life.c 项目: dukelv/csci033
/* Function set_alive

   Given a game board, array, and a row and column (row, col), sets the cell to be alive.  If the cell is not on
   the game board, prints an error message and terminates the program.

   Input: int     rows  - the number of rows of the game board
          int     cols  - the number of columns of the game board
          int[][] array - the game board, a 2D array of zeros and ones
          int     row   - the row of the cell in question
          int     col   - the column of the cell in question

   Output: None
 */
void set_alive(int rows, int cols, int array[rows][cols], int row, int col) {
    /* First, use an assert statement and call is_in_range to confirm the specified cell is on the game board. */
    assert(is_in_range(rows, cols, row, col));

    /* Then, assuming the assert succeeds, set that cell's value to 1 in array.*/
    array[row][col] = 1;

}
示例#21
0
 // Returns the coordinates describing the snake
 std::vector<std::pair<int, int> > get_points(std::pair<int, int> a, std::pair<int, int> b, std::map<std::pair<int, int>, std::pair<int, int>> &father) {
     std::vector<std::pair<int, int> > points;
     // Compute the prefix points of the snake
     while (is_in_range(a)) {
         points.push_back(a);
         auto parent = father[a];
         // We were skipping the equals but now me must take them all
         while (textA[a.first - 1] == textB[a.second - 1]) {
             a.first -= 1;
             a.second -= 1;
             if (is_in_range(a)) {
                 points.push_back(a);
             } else {
                 break;
             }
         }
         a = parent;
     }
     // We need to reverse them as they are in the opposite order
     std::reverse(points.begin(), points.end());
     // Compute the suffix points of the snake (these are inserted in the right order)
     while (is_in_range({b.first, b.second})) {
         points.push_back(b);
         auto parent = father[b];
         // Same thing as in previous while
         while (textA[b.first] == textB[b.second]) {
             b.first += 1;
             b.second += 1;
             if (is_in_range(b)) {
                 points.push_back(b);
             } else {
                 break;
             }
         }
         b = parent;
     }
     // We were working with 1-indexed cells, so we have to decrement them
     for (auto &it : points) {
         it.first -= 1;
         it.second -= 1;
     }
     return points;
 }
示例#22
0
static int test_vbus_shift(void)
{
	system_load_current_ma = 3000;
	/*
	 * At first, the charger is able to supply up to 1900 mA before
	 * the VBUS voltage starts to drop.
	 */
	plug_charger(CHARGE_SUPPLIER_TEST6, 0, 500, 1900, 2000);
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1700, 1900));

	/* The charger heats up and VBUS voltage drops by 100mV */
	vbus_low_current_ma = 1800;
	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1600, 1800));

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
示例#23
0
std::string navteq_2_osm_admin_lvl(std::string navteq_admin_lvl) {
    if (string_is_not_unsigned_integer(navteq_admin_lvl)) throw std::runtime_error("admin level contains invalid character");

    int navteq_admin_lvl_int = stoi(navteq_admin_lvl);

    if (!is_in_range(navteq_admin_lvl_int, NAVTEQ_ADMIN_LVL_MIN, NAVTEQ_ADMIN_LVL_MAX))
        throw std::runtime_error(
                "invalid admin level. admin level '" + std::to_string(navteq_admin_lvl_int) + "' is out of range.");
    return std::to_string(2 * std::stoi(navteq_admin_lvl)).c_str();
}
const modelrange& Modelrangemanager::get_range(index gid) const
{
  if (!is_in_range(gid))
      throw UnknownNode(gid);
  
  for (std::vector<modelrange>::const_iterator it = modelranges_.begin(); it != modelranges_.end(); it++)
    if ( it->is_in_range(gid) )
      return (*it);

  throw UnknownNode(gid);
}
示例#25
0
 bool Time::Exploded::HasValidValues() const
 {
     return is_in_range(month, 1, 12) &&
         is_in_range(day_of_week, 0, 6) &&
         is_in_range(day_of_month, 1, 31) &&
         is_in_range(hour, 0, 23) &&
         is_in_range(minute, 0, 59) &&
         is_in_range(second, 0, 60) &&
         is_in_range(millisecond, 0, 999);
 }
示例#26
0
static int test_vbus_dip(void)
{
	system_load_current_ma = 3000;
	/* VBUS dips too low right before the charger shuts down */
	plug_charger(CHARGE_SUPPLIER_TEST5, 0, 1000, 1500, 1600);

	TEST_ASSERT(wait_stable_no_overcurrent());
	TEST_ASSERT(is_in_range(charge_limit_ma, 1300, 1500));

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
示例#27
0
文件: life.c 项目: dukelv/csci033
/* Function is_alive

   Given a game board, array, and a row and column (row, col), determines if the cell is alive or not.  If the cell
   is not on the game board, returns 0.

   Input: int     rows  - the number of rows of the game board
          int     cols  - the number of columns of the game board
          int[][] array - the game board, a 2D array of zeros and ones
          int     row   - the row of the cell in question
          int     col   - the column of the cell in question

   Output: 1 if the cell is alive (is 1), 0 if it is dead (is 0) or out of range.
 */
int is_alive(int rows, int cols, int array[rows][cols], int row, int col) {
    /* First, determine if the cell is on the game board by calling is_in_range.
       If the result is 1 (true), then return the value of the cell
       Otherwise, return 0.  Unlike with other functions, this should not cause the program to terminate. */
    if(is_in_range(rows, cols, row, col))
    {
	return array[row][col];

    }
    else
    {
	return 0;
    }

}
示例#28
0
static int test_overcurrent(void)
{
	system_load_current_ma = 3000;
	/* Huh...VBUS doesn't dip before the charger shuts down */
	plug_charger(CHARGE_SUPPLIER_TEST6, 0, 500, 3000, 1500);
	usleep(CHARGE_DETECT_DELAY_TEST);
	/* Ramp starts at 500 mA */
	TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));

	while (task_wait_event(RAMP_STABLE_DELAY) == TASK_EVENT_OVERCURRENT) {
		/* Charger goes away but comes back after 0.6 seconds */
		unplug_charger();
		usleep(MSEC * 600);
		plug_charger(CHARGE_SUPPLIER_TEST6, 0, 500, 3000, 1500);
		usleep(CHARGE_DETECT_DELAY_TEST);
		/* Ramp restarts at 500 mA */
		TEST_ASSERT(is_in_range(charge_limit_ma, 500, 700));
	}

	TEST_ASSERT(is_in_range(charge_limit_ma, 1300, 1500));

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
示例#29
0
static int test_full_ramp(void)
{
	system_load_current_ma = 3000;
	/* Now you get to ramp with this 3A charger */
	plug_charger(CHARGE_SUPPLIER_TEST4, 0, 500, 3000, 3000);
	usleep(CHARGE_DETECT_DELAY_TEST);
	/* Start with something around 500 mA */
	TEST_ASSERT(is_in_range(charge_limit_ma, 500, 800));
	TEST_ASSERT(wait_stable_no_overcurrent());
	/* And ramp up to 3A */
	TEST_ASSERT(charge_limit_ma == 3000);

	TEST_ASSERT(unplug_charger_and_check());
	return EC_SUCCESS;
}
示例#30
0
int is_inside_page(modelica_metatype p)
{
  mmc_GC_page_type page;
  size_t i = 0;

  for(i = 0; i < mmc_GC_state->mas.pages.current; i++)
  {
    page = mmc_GC_state->mas.pages.start[i];
    if (is_in_range(p, page.start, page.size))
    {
      return 1;
    }
  }

  return 0;
}