text:
/*********************************************************************/
/* Copyright (c) 2011 - 2012, The University of Texas at Austin.     */
/* All rights reserved.                                              */
/*                                                                   */
/* Redistribution and use in source and binary forms, with or        */
/* without modification, are permitted provided that the following   */
/* conditions are met:                                               */
/*                                                                   */
/*   1. Redistributions of source code must retain the above         */
/*      copyright notice, this list of conditions and the following  */
/*      disclaimer.                                                  */
/*                                                                   */
/*   2. Redistributions in binary form must reproduce the above      */
/*      copyright notice, this list of conditions and the following  */
/*      disclaimer in the documentation and/or other materials       */
/*      provided with the distribution.                              */
/*                                                                   */
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
/*                                                                   */
/* The views and conclusions contained in the software and           */
/* documentation are those of the authors and should not be          */
/* interpreted as representing official policies, either expressed   */
/* or implied, of The University of Texas at Austin.                 */
/*********************************************************************/

#ifndef DISPLAY_GROUP_GRAPHICS_VIEW_H
#define DISPLAY_GROUP_GRAPHICS_VIEW_H

#include <QtGui>

class PanGesture;
class PinchGesture;

class DisplayGroupGraphicsView : public QGraphicsView
{
    Q_OBJECT

public:
    DisplayGroupGraphicsView();
    virtual ~DisplayGroupGraphicsView();

    void grabGestures();

signals:
    void backgroundTap(QPointF pos);
    void backgroundTapAndHold(QPointF pos);

protected:
    virtual bool viewportEvent( QEvent* event );
    virtual void resizeEvent( QResizeEvent* event );

    void gestureEvent( QGestureEvent* event );
    void swipe( QSwipeGesture* gesture );
    void pan( PanGesture* gesture );
    void pinch( PinchGesture* gesture );
    void tap( QTapGesture* gesture );
    void tapAndHold( QTapAndHoldGesture* gesture );

private:
    QPointF getNormalizedPosition( const QGesture* gesture ) const;
    bool isOnBackground( const QPointF& position ) const;
};

#endif


text:
module StateMachine

  # See subclasses for various transition implementations.
  # Sorry for putting multiple classes in one file —
  # RubyMotion has no decentral dependency management yet...

  # @abstract Subclass and override {#event_description}, {#arm} and {#unarm} to implement a custom Transition class.

  class Transition

    # @return [Hash] configuration options of the transition.
    attr_reader :options

    # @return [Base] the state machine that this transition belongs to.
    attr_reader :state_machine

    # @return [State] the state from which the transition starts.
    attr_reader :source_state

    # @return [State] the state that the transition leads to.
    attr_reader :destination_state

    # @return [Object] a more specific object that triggers
    #   the transition.
    attr_reader :event_trigger_value

    class << self
      # @return [Symbol] Metaclass attribute, contains the key that
      #   is used for generating the specific transition via {#make}.
      attr_accessor :event_type
    end

    @@types_to_subclasses = {}

    # @return [Array<Class<Transition>>] a list of all registered transition subclasses
    def self.types
      @@types_to_subclasses.keys
    end

    # Creates a new {Transition} object with the given options.
    # The returned object's subclass is determined by the
    # +:type+ option.
    #
    # @param options [Hash] Configuration options for the transition.
    # @option options [Symbol] :type Type identifier for the transition, ex. +:on+, +:after+, +:on_notification+.
    #
    # See {#initialize} for all possible options.
    #
    # @example
    #   StateMachine::Transition.make type: :to, ... # => #<StateMachine::Transition:...>
    # @return [Transition] a new object with the class that fits the given +:type+ option.

    def self.make(options)
      klass = @@types_to_subclasses[options[:type]]
      klass.new options
    end

    # Initializes a new {Transition} between two given states.
    #
    # Additionally, you must also supply an event trigger value as
    # option. Its key must be equal to the transition class's
    # +event_type+., ex. if +event_type+ is +:on+, you have to supply
    # the event value using the option key +:on+.
    #
    # @param options [Hash] Configuration options for the transition.
    #
    # @option options [StateMachine::Base] :state_machine
    #   State machine that the transition belongs to.
    #
    # @option options [Symbol] :from
    #   State where the transition begins.
    #
    # @option options [Symbol] :to
    #   State where the transition ends.
    #
    # @option options [Proc] :if (nil)
    #   Block that should return a +Boolean+. If the block returns
    #   +false+, the transition will be blocked and not executed
    #   (optional).
    #
    # @option options [Proc] :unless (nil)
    #   Block that should return a +Boolean+. If the block returns
    #   +true+, the transition will be blocked and not executed
    #   (optional).
    #
    # @option options [Boolean] :internal (false)
    #   If set to true, the transition will not leave it's source
    #   state: Entry and Exit actions will not be called in this case.
    #   For internal transitions, +:from+ and +:to+ must be the same
    #   (optional).
    #
    # @note This method should not be used directly. To create +Transition+ objects, use {#make} instead.

    def initialize(options)
      @options = options.dup
      @state_machine = @options.delete :state_machine
      @source_state = @state_machine.state options[:from]
      @destination_state = @state_machine.state options[:to]

      event_type = self.class.event_type
      if event_type.nil?
        raise RuntimeError, "#{self.class} has no defined event type."
      end

      [:from, :to].each do |symbol|
        unless options[symbol].is_a?(Symbol)
          raise ":#{symbol} option must be given as symbol."
        end
      end

      @event_trigger_value = options[event_type]
      if @event_trigger_value.nil?
        raise ArgumentError, "You must supply an event trigger value."
      end

      if options[:internal] && options[:from] != options[:to]
        raise ArgumentError,
          "Internal states must have same source and destination state."
      end
    end

    # @return [Boolean] Asks the guard blocks given for +:if+ and
    #   +:unless+ if the transition is allowed. Returns +true+ if the
    #   transition is allowed to be executed.

    def allowed?
      if_guard = options[:if]
      unless if_guard.nil?
        return false unless if_guard.call(@state_machine)
      end
      unless_guard = options[:unless]
      unless unless_guard.nil?
        return false if unless_guard.call(@state_machine)
      end
      true
    end

    # @return [String] a short description of the event.
    #   Used for debug output.

    def event_description
      # Implement this in a subclass.
      "after unclassified event"
    end

    def inspect
      "#<#{self.class.name}:0x#{object_id.to_s(16)} "\
      "#{event_description} @options=#{options.inspect}>"
    end

    protected

    # Defines a +Hash+ key symbol that is unique to a {Transition}
    # subclass. The key is used by {#make} to identify which
    # {Transition} subclass should be created.
    #
    # @param [Symbol] type_symbol
    #   Unique symbol identifying your transition subclass.

    def self.type(type_symbol)
      unless type_symbol.is_a?(Symbol)
        raise ArgumentError, "Type must be given as symbol."
      end
      if @@types_to_subclasses[type_symbol].nil?
        @@types_to_subclasses[type_symbol] = self
      else
        other_class = @@types_to_subclasses[type_symbol]
        raise ArgumentError,
          "Can't register :#{type_symbol} twice, "
          "already used by #{other_class}."
      end
      @event_type = type_symbol
    end

    # Delegates handling the transition to the source state, which
    # makes sure that there are no ambiguous transitions for the
    # same event.

    def handle_in_source_state
      if @state_machine.initial_queue.nil?
        raise RuntimeError, "State machine not started yet."
      end

      if Dispatch::Queue.current.to_s != @state_machine.initial_queue.to_s
        raise RuntimeError,
          "#{self.class.event_type}:#{@event_trigger_value} must be "\
          "called from the queue where the state machine was started."
      end

      @source_state.send :guarded_execute,
        self.class.event_type,
        @event_trigger_value
    end

    private

    # Executed the transition directly, without checking the guard
    # blocks. Calls {State#exit!} on the source state, executes
    # the transition's +:action+ block and calls {State#enter!} on
    # the destination state.

    def unguarded_execute
      @source_state.send :exit! unless @options[:internal] == true
      # Could use @state_machine.instance_eval(&options[:action]) here,
      # but this would be much slower
      @options[:action] && @options[:action].call(@state_machine)
      @destination_state.send :enter! unless @options[:internal] == true

      @state_machine.log "#{event_log_text}"
    end

    # @return [String] Debug string that can be logged after the
    #   transition has been executed.

    def event_log_text
  		if @options[:internal]
  			"#{@state_machine.name} still #{destination_state.name} "\
        "#{event_description} (internal transition, not exiting state)."
  		else
				"#{@state_machine.name} #{destination_state.name} "\
        "#{event_description}."
      end
    end

    # Called by source {State} when it is entered. Allows the
    # transition to initialize a mechanism that catches its trigger
    # event. Override this in a subclass.

    def arm
    end

    # Called by source {State} when it is exited. Subclass
    # implementations should deactivate their triggering
    # mechanism in this method.

    def unarm
    end

  end

  # This is kind of the 'standard' transition. It is created when
  # supplying the +:on+  option in the state machine definition.
  #
  # If armed, the transition is triggered when sending an event to the
  # state machine by calling {StateMachine::Base#event} with the
  # event's symbol as parameter. Sending the same event symbol while
  # not armed will just ignore the event.
  #
  # Note that you should call the {StateMachine::Base#event} method
  # from the same queue / thread where the state machine was started.
  #
  # @example Create a {SendEventTransition}:
  #
  #   state_machine.when :sleeping do |state|
  #     state.transition_to :awake, on: :foo
  #   end
  #
  #   state_machine.event :foo
  #     # => state machine goes to :awake state

  class SendEventTransition < Transition
    type :on

    def initialize(options)
      super(options)
      unarm
    end

    def event_description
      "after #{event_trigger_value}"
    end

    def arm
      state_machine.register_event_handler event_trigger_value, self
    end

    def unarm
      state_machine.register_event_handler event_trigger_value, nil
    end
  end

  # Transitions of this type are triggered on a given timeout (in
  # seconds). Created when supplying an :after option in the transition
  # definition.
  #
  # The timeout is canceled when the state is left.
  #
  # The transition uses Grand Central Dispatch's timer source
  # mechanism: It adds a timer source to the state machine's initial
  # GCD queue.
  #
  # The system tries to achieve an accuracy of 1 millisecond for the
  # timeout. You can change this behavior to trade timing accuracy vs.
  # system performance by using the +leeway+ option (given in seconds).
  # See {http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man3/dispatch_source_set_timer.3.html Apple's GCD documentation}
  # for more information about this parameter.
  #
  # @example Create a transition that timeouts after 8 hours:
  #
  #   state_machine.when :sleeping do |state|
  #     # Timeout after 28800 seconds
  #     state.transition_to :awake, after: 8 * 60 * 60
  #   end

  class TimedTransition < Transition
    type :after

    def event_description
      "after #{event_trigger_value} seconds of "\
      "#{source_state.name} (timeout)"
    end

    #
    def arm
      @state_machine.log "Starting timeout -> #{options[:to]}, "\
        "after #{options[:after]}"
      delay = event_trigger_value
      interval = Dispatch::TIME_FOREVER
      leeway = @options[:leeway] || 0.001
      queue = @state_machine.initial_queue
      @timer = Dispatch::Source.timer(delay, interval, leeway, queue) do
        @state_machine.log "Timeout!"
        self.handle_in_source_state
      end
    end

    def unarm
      @state_machine.log "Timer unarmed"
      @timer.cancel!
    end

  end

  # Triggered on a specified +NSNotification+ name. Created when
  # supplying an +:on_notification+ option in the transition definition.
  #
  # On entering the source state, the transition registers itself as
  # +NSNotification+ observer on the default +NSNotificationCenter+. It
  # deregisters when the state is exited.
  #
  # @example
  #   state_machine.when :awake do |state|
  #     state.transition_to :sleeping,
  #       on_notificaiton: UIApplicationDidEnterBackgroundNotification
  #   end

  class NotificationTransition < Transition
    type :on_notification

    def initialize(options)
      super options
    end

    def event_description
      "after getting a #{event_trigger_value}"
    end

    def arm
      @observer = NSNotificationCenter.defaultCenter.addObserverForName event_trigger_value,
        object: nil,
        queue: NSOperationQueue.mainQueue,
        usingBlock: -> notification {
          handle_in_initial_queue
          state_machine.log "Registered notification #{event_trigger_value}"
        }
    end

    def unarm
      NSNotificationCenter.defaultCenter.removeObserver @observer
      @state_machine.log "Removed as observer"
    end

    private

    # This makes sure that state entry/exit and transition actions are
    # called within the initial queue/thread.

    def handle_in_initial_queue
      if state_machine.initial_queue.to_s == Dispatch::Queue.main.to_s
        handle_in_source_state
      else
        state_machine.initial_queue.async do
          handle_in_source_state
        end
      end
    end

  end

end

redpajama_set_name: RedPajamaGithub


text:
var _ = require('lodash')
var exp = module.exports

exp.prettyNumber = function(n) {
    if (!_.isNumber(n)) {
        return n
    }
    var ugly = n.toString()
    var pretty = ''
    var index = 0
    for (var i = ugly.length - 1; i >=0; i--) {
        pretty += ugly.substring(i, i+1)
        if (++index % 3 === 0 && index < ugly.length) {
            pretty += ','
        }
    }
    return pretty.split('').reverse().join('')
}

exp.pValueToReadable = function(p) {
    if (!_.isNumber(p)) {
        return NaN
    }
    var pReadable = p
    //negative P-value is impossible; javascript flips to negative zero if the minimum value is exceeded, so need to state it is smaller than the min value in JS
    if(p <= 0){
        pReadable = '<' + Number.MIN_VALUE;
    }
    else if (p < 0.01) {
        pReadable = pReadable.toExponential(1)
        var expIndex = pReadable.indexOf('e')
        var base = pReadable.substring(0, expIndex)
        var exponent = pReadable.substring(expIndex + 1)
        // TODO vertically align 'x' to middle (vertical-align, line-height, padding don't seem to work)
        pReadable = base + ' x 10' + exponent + ''
        if (p === Number.MIN_VALUE) {
            pReadable = '< ' + pReadable
        }
    }
    else {
        pReadable = pReadable.toPrecision(1)
    }
    return pReadable
}

exp.intToStr = function(value) {
    if (!_.isNumber(value)) {
        return value
    }
    if (value === 10) {
        return 'ten'
    } else if (value === 9) {
        return 'nine'
    } else if (value === 8) {
        return 'eight'
    } else if (value === 7) {
        return 'seven'
    } else if (value === 6) {
        return 'six'
    } else if (value === 5) {
        return 'five'
    } else if (value === 4) {
        return 'four'
    } else if (value === 3) {
        return 'three'
    } else if (value === 2) {
        return 'two'
    } else if (value === 1) {
        return 'one'
    } else if (value === 0) {
        return 'zero'
    }
    else return value + ''
}

exp.intToOrdinalStr = function(value) {
    if (!_.isNumber(value)) {
        return value
    }
    if (value === 10) {
        return 'tenth'
    } else if (value === 9) {
        return 'ninth'
    } else if (value === 8) {
        return 'eighth'
    } else if (value === 7) {
        return 'seventh'
    } else if (value === 6) {
        return 'sixth'
    } else if (value === 5) {
        return 'fifth'
    } else if (value === 4) {
        return 'fourth'
    } else if (value === 3) {
        return 'third'
    } else if (value === 2) {
        return 'second'
    } else if (value === 1) {
        return 'first'
    } else if (value === 0) {
        return 'immediately preceding what is regarded as first in a series'
    }
    else if (value < 20) {
        return value + 'th'
    } else {
        value = value + ''
        if (value.endsWith('1')) {
            return value + 'st'
        } else if (value.endsWith('2')) {
            return value + 'nd'
        } else if (value.endsWith('3')) {
            return value + 'rd'
        } else {
            return value + 'th'
        }
    }
    return value + 'th'
}


text:
#ifndef _util_h
#define _util_h

#include "global.h"
#include <ncurses.h>

/* UI colors: (foreground, background, attrs)
 *  NAME         OFF                        DARK
 */
#define UI_COLORS \
  C(DEFAULT,     -1,-1,0               ,    -1,           -1,         0     )\
  C(BOX_TITLE,   -1,-1,A_BOLD          ,    COLOR_BLUE,   -1,         A_BOLD)\
  C(HD,          -1,-1,A_REVERSE       ,    COLOR_BLACK,  COLOR_CYAN, 0     )    /* header & footer */\
  C(SEL,         -1,-1,A_REVERSE       ,    COLOR_WHITE,  COLOR_GREEN,A_BOLD)\
  C(NUM,         -1,-1,0               ,    COLOR_YELLOW, -1,         A_BOLD)\
  C(NUM_HD,      -1,-1,A_REVERSE       ,    COLOR_YELLOW, COLOR_CYAN, A_BOLD)\
  C(NUM_SEL,     -1,-1,A_REVERSE       ,    COLOR_YELLOW, COLOR_GREEN,A_BOLD)\
  C(KEY,         -1,-1,A_BOLD          ,    COLOR_YELLOW, -1,         A_BOLD)\
  C(KEY_HD,      -1,-1,A_BOLD|A_REVERSE,    COLOR_YELLOW, COLOR_CYAN, A_BOLD)\
  C(DIR,         -1,-1,0               ,    COLOR_BLUE,   -1,         A_BOLD)\
  C(DIR_SEL,     -1,-1,A_REVERSE       ,    COLOR_BLUE,   COLOR_GREEN,A_BOLD)\
  C(FLAG,        -1,-1,0               ,    COLOR_RED,    -1,         0     )\
  C(FLAG_SEL,    -1,-1,A_REVERSE       ,    COLOR_RED,    COLOR_GREEN,0     )\
  C(GRAPH,       -1,-1,0               ,    COLOR_MAGENTA,-1,         0     )\
  C(GRAPH_SEL,   -1,-1,A_REVERSE       ,    COLOR_MAGENTA,COLOR_GREEN,0     )

enum ui_coltype {
#define C(name, ...) UIC_##name,
  UI_COLORS
#undef C
  UIC_NONE
};

/* Color & attribute manipulation */
extern int uic_theme;

void uic_init();
void uic_set(enum ui_coltype);

/* updated when window is resized */
extern int winrows, wincols;

/* used by the nc* functions and macros */
extern int subwinr, subwinc;

/* used by formatsize to choose between base 2 or 10 prefixes */
extern int si;

/* Macros/functions for managing struct dir and struct dir_ext */

#define dir_memsize(n)     (offsetof(struct dir, name)+1+strlen(n))
#define dir_ext_offset(n)  ((dir_memsize(n) + 7) & ~7)
#define dir_ext_memsize(n) (dir_ext_offset(n) + sizeof(struct dir_ext))

static inline struct dir_ext *dir_ext_ptr(struct dir *d) {
  return d->flags & FF_EXT
    ? (struct dir_ext *) ( ((char *)d) + dir_ext_offset(d->name) )
    : NULL;
}

/* Instead of using several ncurses windows, we only draw to stdscr.
 * the functions nccreate, ncprint and the macros ncaddstr and ncaddch
 * mimic the behaviour of ncurses windows.
 * This works better than using ncurses windows when all windows are
 * created in the correct order: it paints directly on stdscr, so
 * wrefresh, wnoutrefresh and other window-specific functions are not
 * necessary.
 * Also, this method doesn't require any window objects, as you can
 * only create one window at a time.
*/

/* updates winrows, wincols, and displays a warning when the terminal
 * is smaller than the specified minimum size. */
int ncresize(int, int);

/* creates a new centered window with border */
void nccreate(int, int, const char *);

/* printf something somewhere in the last created window */
void ncprint(int, int, char *, ...);

/* Add a "tab" to a window */
void nctab(int, int, int, char *);

/* same as the w* functions of ncurses, with a color */
#define ncaddstr(r, c, s) mvaddstr(subwinr+(r), subwinc+(c), s)
#define  ncaddch(r, c, s)  mvaddch(subwinr+(r), subwinc+(c), s)
#define   ncmove(r, c)        move(subwinr+(r), subwinc+(c))

/* add stuff with a color */
#define mvaddstrc(t, r, c, s) do { uic_set(t); mvaddstr(r, c, s); } while(0)
#define  mvaddchc(t, r, c, s) do { uic_set(t);  mvaddch(r, c, s); } while(0)
#define   addstrc(t,       s) do { uic_set(t);   addstr(      s); } while(0)
#define    addchc(t,       s) do { uic_set(t);    addch(      s); } while(0)
#define ncaddstrc(t, r, c, s) do { uic_set(t); ncaddstr(r, c, s); } while(0)
#define  ncaddchc(t, r, c, s) do { uic_set(t);  ncaddch(r, c, s); } while(0)
#define  mvhlinec(t, r, c, s, n) do { uic_set(t);  mvhline(r, c, s, n); } while(0)

/* crops a string into the specified length */
char *cropstr(const char *, int);

/* Converts the given size in bytes into a float (0 <= f < 1000) and a unit string */
float formatsize(int64_t, char **);

/* print size in the form of xxx.x XB */
void printsize(enum ui_coltype, int64_t);

/* int2string with thousand separators */
char *fullsize(int64_t);

/* format's a file mode as a ls -l string */
char *fmtmode(unsigned short);

/* read locale information from the environment */
void read_locale();

/* recursively free()s a directory tree */
void freedir(struct dir *);

/* generates full path from a dir item,
   returned pointer will be overwritten with a subsequent call */
char *getpath(struct dir *);

/* returns the root element of the given dir struct */
struct dir *getroot(struct dir *);

/* Add two signed 64-bit integers. Returns INT64_MAX if the result would
 * overflow, or 0 if it would be negative. At least one of the integers must be
 * positive.
 * I use uint64_t's to detect the overflow, as (a + b < 0) relies on undefined
 * behaviour, and (INT64_MAX - b >= a) didn't work for some reason. */
#define adds64(a, b) ((a) > 0 && (b) > 0\
    ? ((uint64_t)(a) + (uint64_t)(b) > (uint64_t)INT64_MAX ? INT64_MAX : (a)+(b))\
    : (a)+(b) < 0 ? 0 : (a)+(b))

/* Adds a value to the size, asize and items fields of *d and its parents */
void addparentstats(struct dir *, int64_t, int64_t, uint64_t, int);

/* A simple stack implemented in macros */
#define nstack_init(_s) do {\
    (_s)->size = 10;\
    (_s)->top = 0;\
    (_s)->list = malloc(10*sizeof(*(_s)->list));\
  } while(0)

#define nstack_push(_s, _v) do {\
    if((_s)->size <= (_s)->top) {\
      (_s)->size *= 2;\
      (_s)->list = realloc((_s)->list, (_s)->size*sizeof(*(_s)->list));\
    }\
    (_s)->list[(_s)->top++] = _v;\
  } while(0)

#define nstack_pop(_s) (_s)->top--
#define nstack_top(_s, _d) ((_s)->top > 0 ? (_s)->list[(_s)->top-1] : (_d))
#define nstack_free(_s) free((_s)->list)

#endif


text:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*                                                                       */
/*    This file is part of the HiGHS linear optimization suite           */
/*                                                                       */
/*    Written and engineered 2008-2020 at the University of Edinburgh    */
/*                                                                       */
/*    Available as open-source under the MIT License                     */
/*                                                                       */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file lp_data/HighsDebug.cpp
 * @brief
 * @author Julian Hall, Ivet Galabova, Qi Huangfu and Michael Feldmeier
 */
#include "lp_data/HighsDebug.h"

#include <algorithm>  // For std::max
#include <cassert>    // For std::max

HighsStatus debugDebugToHighsStatus(const HighsDebugStatus debug_status) {
  switch (debug_status) {
    case HighsDebugStatus::NOT_CHECKED:
    case HighsDebugStatus::OK:
    case HighsDebugStatus::SMALL_ERROR:
      return HighsStatus::OK;
    case HighsDebugStatus::WARNING:
    case HighsDebugStatus::LARGE_ERROR:
      return HighsStatus::Warning;
    case HighsDebugStatus::ERROR:
    case HighsDebugStatus::EXCESSIVE_ERROR:
    case HighsDebugStatus::LOGICAL_ERROR:
      return HighsStatus::Error;
    default:
      return HighsStatus::OK;
  }
}

HighsDebugStatus debugWorseStatus(const HighsDebugStatus status0,
                                  const HighsDebugStatus status1) {
  return static_cast<HighsDebugStatus>(std::max((int)status0, (int)status1));
}

bool debugVectorRightSize(const std::vector<double> v, const int right_size) {
  const int v_size = v.size();
  const bool is_right_size = v_size == right_size;
  assert(is_right_size);
  return is_right_size;
}

bool debugVectorRightSize(const std::vector<int> v, const int right_size) {
  const int v_size = v.size();
  const bool is_right_size = v_size == right_size;
  assert(is_right_size);
  return is_right_size;
}